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的AC代码,具体就不解释了XDIn Reply To:25行代码流出 Posted by:Sayakiss at 2010-08-09 18:51:37 #include<iostream> #include<cstring> using namespace std; long long f[2][1<<12],i,j,ps,p=0,c=1,n,m; int main() { while (scanf("%d%d",&n,&m),n!=0) { memset(f[c],0,sizeof(f[c])); f[c][(1<<m)-1]=1; for (i=0;i<n;i++) for (j=0;j<m;j++) { swap(p,c);memset(f[c],0,sizeof(f[c])); for (ps=0;ps<1<<m;ps++) if (f[p][ps]) { if (j>0&&(!(ps&(1<<j-1)))&&(ps&(1<<j))) f[c][ps|1<<(j-1)]+=f[p][ps]; if (!(ps&1<<j)) f[c][ps|1<<j]+=f[p][ps]; if (ps&1<<j) f[c][ps^1<<j]+=f[p][ps]; } } printf("%lld\n",f[c][(1<<m)-1]); } } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator