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 |
第一次写状态DP的程序就超时了,哪位帮我看看,先谢过了!#include "stdio.h" #include "stdlib.h" int a[21][1<<20]={0},b[30][30]={0},n,m; int fd(int bull,int ban) { if(a[bull][ban]) return a[bull][ban]; if(bull==1) { int sum=0,i=1,j=ban; while(j) { if((j&1)&&b[bull][i]==1) sum++; j=(j>>1),i++; } a[bull][ban]=sum; return sum; } else { int i; for(i=1;i<=m;i++) { if(b[bull][i]==1) { if((ban>>(i-1))&1) { int k=0,s=ban-(1<<(i-1)); while(s) { if(s&1) k++; s=(s>>1); } if(k>=bull-1) a[bull][ban]+=fd(bull-1,ban-(1<<(i-1))); } } } return a[bull][ban]; } } int main() { int i,j,k,l; scanf("%d %d",&n,&m); for(i=1;i<=n;i++) { scanf("%d",&k); for(j=1;j<=k;j++) { scanf("%d",&l); b[i][l]=1; } } printf("%d\n",fd(n,(1<<m)-1)); return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator