标签:
除了在3个格子中都放满炮的的情况外,其它的都可以.
100%的数据中N,M不超过100
50%的数据中,N,M至少有一个数不超过8
30%的数据中,N,M均不超过6
#include<cstdio> #include<iostream> #include<cstring> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<deque> #include<set> #include<map> #include<ctime> #define LL long long #define inf 0x7ffffff #define pa pair<int,int> #define mod 9999973 using namespace std; inline LL read() { LL x=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();} while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();} return x*f; } inline void write(LL a) { if (a<0){printf("-");a=-a;} if (a>=10)write(a/10); putchar(a%10+‘0‘); } inline void writeln(LL a){write(a);printf("\n");} LL f[110][110][110]; int n,m; LL ans; inline LL calc(LL x){return x*(x-1)/2;} int main() { n=read();m=read(); f[0][0][0]=1; for (int i=1;i<=n;i++) for (int j=0;j<=m;j++) for (int k=0;k<=m-j;k++) { f[i][j][k]=f[i-1][j][k];//(1) if (j)f[i][j][k]+=f[i-1][j-1][k]*(m-k-j+1);//(2) if (j<m&&k)f[i][j][k]+=f[i-1][j+1][k-1]*(j+1);//(3) if (j&&k)f[i][j][k]+=f[i-1][j][k-1]*j*(m-j-k+1);//(4) if (j>1)f[i][j][k]+=f[i-1][j-2][k]*calc(m-k-j+2);//(5) if (j<=m-2&&k>1)f[i][j][k]+=f[i-1][j+2][k-2]*calc(j+2);//(6) f[i][j][k]%=mod; } for (int i=0;i<=m;i++) for (int j=0;j<=m-i;j++) ans=(ans+f[n][i][j])%mod; printf("%lld\n",ans); }
标签:
原文地址:http://www.cnblogs.com/zhber/p/4183238.html