Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
25行代码...状态压缩DP+滚动数组#include<stdio.h> #include<string.h> const int N=12,MOD=100000000; int map[N][N],f[2][(1<<N)+10],n,m; int main() { int i,j,k,p,ans; while(~scanf("%d%d",&n,&m)){ ans=0;memset(f,0,sizeof(f));f[0][0]=p=1; for(i=0;i<n;i++) for(j=0;j<m;j++) scanf("%d",&map[i][j]); for(i=0;i<n;i++) for(j=0;j<m;j++,memset(f[p=!p],0,sizeof(f[0]))) for(k=0;k<(1<<m);k++) if(k&(1<<j)) f[p][k&~(1<<j)]=(f[p][k&~(1<<j)]+f[!p][k])%MOD; else { f[p][k]=(f[p][k]+f[!p][k])%MOD; if((j && !(k&(1<<(j-1))) || !j ) && map[i][j]) f[p][k|(1<<j)]=(f[p][k|(1<<j)]+f[!p][k])%MOD; } for(i=0,p=!p;i<(1<<m);i++)ans=(ans+f[p][i])%MOD; printf("%d\n",ans); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator