标签:sizeof opened strong 状态 memory exp fine include pre
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 18023 | Accepted: 10327 |
Description
Input
Output
Sample Input
1 2
1 3
1 4
2 2
2 3
2 4
2 11
4 11
0 0
Sample Output
1
0
1
2
3
5
144
51205
Source
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<vector> 5 #define LL long long 6 #define idx(x,i) ((x>>i)&1) 7 using namespace std; 8 const int lim=20; 9 int n,m,S; LL f[lim][1<<lim]; 10 vector <int> o[1<<lim]; 11 bool jug(int su,int sd) { 12 for (int i=0; i<m; i++) { 13 int ku=idx(su,i),kd=idx(sd,i); 14 if (!kd&&ku) continue; 15 if (ku) return 0; else 16 if (!kd) { 17 if (i<m-1&&!idx(su,i+1)) su|=1<<(i+1); else return 0; 18 } 19 } 20 return 1; 21 } 22 int main() { 23 while (scanf("%d%d",&n,&m),n|m) { 24 S=1<<m; 25 for (int i=0; i<S; i++) o[i].clear(); 26 for (int i=0; i<S; i++) 27 for (int j=0; j<S; j++) if (jug(i,j)) o[j].push_back(i); 28 memset(f,0,sizeof f),f[0][0]=1; 29 for (int i=1; i<=n; i++) 30 for (int j=0; j<S; j++) 31 for (int k=0,s=o[j].size(); k<s; k++) 32 f[i][j]+=f[i-1][o[j][k]]; 33 printf("%lld\n",f[n][0]); 34 } 35 return 0; 36 }
标签:sizeof opened strong 状态 memory exp fine include pre
原文地址:http://www.cnblogs.com/whc200305/p/7678298.html