2018杭電多校第九場
阿新 • • 發佈:2018-12-24
A
#include <iostream> #include <cmath> #include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <cassert> using namespace std; const int N=82; int dp[2][N][N],mo; int n,m; void update(int &k1,long long k2){ k1=(k1+k2)%mo; } void solve(){ scanf("%d%d%d",&n,&m,&mo); memset(dp,0x00,sizeof dp); dp[0][1][1]=n*m; int now=0; for (int i=2;i<=n*m;i++){ int ne=now^1; memset(dp[ne],0x00,sizeof dp[ne]); for (int j=0;j<=n;j++) for (int k=0;k<=m;k++) if (dp[now][j][k]){ // cout<<i<<" "<<j<<" "<<k<<" "<<dp[now][j][k]<<endl; int k1=dp[now][j][k]; int tot=j*k-i+1,ex1; update(dp[ne][j][k],1ll*k1*(j*k-i+1)); update(dp[ne][j+1][k],1ll*k1*k*(n-j)); update(dp[ne][j][k+1],1ll*k1*j*(m-k)); } now=ne; } printf("%d\n",dp[now][n][m]); } int main(){ int t; scanf("%d",&t); for (;t;t--) solve(); return 0; }
D
#include <iostream> #include <cmath> #include <cstring> #include <cstdio> #include <algorithm> #include <vector> #include <cassert> using namespace std; int A[3],B[3]; void solve(){ for (int i=0;i<3;i++) scanf("%d",&A[i]); for (int i=0;i<3;i++) scanf("%d",&B[i]); long long ans=0; long long n=1ll*A[0]+A[1]+A[2]; assert(n==1ll*B[0]+B[1]+B[2]); for (int i=0;i<3;i++) for (int j=0;j<3;j++) if (j==(i+1)%3) ans+=1ll*A[i]*B[j]; else if (i!=j) ans-=1ll*A[i]*B[j]; long long d=abs(__gcd(ans,1ll*n)); long long k1=ans/d,k2=n/d; if (k2==1) printf("%lld\n",k1); else printf("%lld/%lld\n",k1,k2); } int main(){ int t; scanf("%d",&t); for (;t;t--) solve(); return 0; }
K
#include <iostream> #include <cmath> #include <cstring> #include <cstdio> #include <algorithm> using namespace std; const int mo=998244353; int quick(int k1,int k2){ int k3=1; while (k2){ if (k2&1) k3=1ll*k3*k1%mo; k2>>=1; k1=1ll*k1*k1%mo; } return k3; } int dp[2][3],A[2][3],f[2][3]; void update(int &k1,long long k2){ k1=(k1+k2)%mo; } void update(){ memcpy(f,dp,sizeof dp); memset(dp,0x00,sizeof dp); for (int i=0;i<2;i++) for (int j=0;j<3;j++) for (int k=0;k<2;k++) for (int a=0;a<3;a++){ update(dp[min(i+k,1)][min(j+a,2)],1ll*A[i][j]*f[k][a]); } } void solve(){ int a,b,c,d; scanf("%d%d%d%d",&a,&b,&c,&d); memset(dp,0x00,sizeof dp); dp[0][0]=quick(2,a); memset(A,0x00,sizeof A); A[0][0]=1; A[0][1]=b; A[0][2]=(quick(2,b)-b-1+mo)%mo; update(); memset(A,0x00,sizeof A); A[0][0]=1; A[1][0]=(quick(2,c)-1)%mo; update(); memset(A,0x00,sizeof A); A[0][0]=1; A[1][1]=d; A[1][2]=(quick(2,d)-d-1+mo)%mo; update(); int ans=(quick(2,a+b+c+d)-dp[1][2]+mo)%mo; printf("%d\n",ans); } int main(){ int t; scanf("%d",&t); for (;t;t--) solve(); return 0; }