SGU 131 状态压缩dp
2012-03-31 18:27
411 查看
#include<iostream> #include<vector> #include<algorithm> #include<cstdio> #include<queue> #include<stack> #include<string> #include<map> #include<set> #include<cmath> #include<cassert> #include<cstring> #include<iomanip> using namespace std; #ifdef _WIN32 #define i64 __int64 #define out64 "%I64d\n" #define in64 "%I64d" #else #define i64 long long #define out64 "%lld\n" #define in64 "%lld" #endif #define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++) #define FF(i,a) for( int i = 0 ; i < (a) ; i ++) #define FFD(i,a) for( int i = (a)-1 ; i >= 0 ; i --) #define S64(a) scanf(in64,&a) #define SS(a) scanf("%d",&a) #define LL(a) ((a)<<1) #define RR(a) (((a)<<1)+1) #define SZ(a) ((int)a.size()) #define PP(n,m,a) puts("---");FF(i,n){FF(j,m)cout << a[i][j] << ' ';puts("");} #define pb push_back #define CL(Q) while(!Q.empty())Q.pop() #define MM(name,what) memset(name,what,sizeof(name)) #define read freopen("in.txt","r",stdin) #define write freopen("out.txt","w",stdout) const int inf = 0x3f3f3f3f; const i64 inf64 = 0x3f3f3f3f3f3f3f3fLL; const double oo = 10e9; const double eps = 10e-10; const double pi = acos(-1.0); const int maxn = 9; const int maxc = 12; i64 dp[maxc][1<<maxn]; int n,m; int seed; void dfs(int k,int x,int now,int to,bool up,bool down) { if(x==m+1) { if(!up && !down ) { dp[k+1][to] += dp[k][now^seed]; } return ; } if(!up && !down) { dfs(k,x+1,now<<1,to<<1,false,false); dfs(k,x+1,now<<1|1,to<<1|1,false,false); dfs(k,x+1,now<<1|1,to<<1|1,true,false); dfs(k,x+1,now<<1|1,to<<1|1,false,true); dfs(k,x+1,now<<1|1,to<<1,true,true); dfs(k,x+1,now<<1,to<<1|1,true,true); // dfs(k,x+1,now<<1|1,to<<1,true,false); dfs(k,x+1,now<<1,to<<1|1,false,true); // dfs(k,x+1,now<<1|1,to<<1|1,true,true); } else if(up && !down) { dfs(k,x+1,now<<1|1,to<<1,false,false); dfs(k,x+1,now<<1|1,to<<1|1,true,true); dfs(k,x+1,now<<1|1,to<<1|1,false,true); } else if(!up && down) { dfs(k,x+1,now<<1,to<<1|1,false,false); // dfs(k,x+1,now<<1|1,to<<1|1,true,false); dfs(k,x+1,now<<1|1,to<<1|1,true,true); } else if(up && down) { dfs(k,x+1,now<<1|1,to<<1|1,false,false); } return ; } i64 start() { MM(dp,0); dp[0][(1<<m)-1]=1; seed = (1<<m)-1; FF(i,n) { dfs(i,1,0,0,0,0); } return dp [(1<<m)-1]; } int main() { while(cin>>n>>m) { cout<<start()<<endl; } return 0; }
相关文章推荐
- 状态压缩DP——SGU 131
- SGU 131 贴地砖类型 状态压缩DP
- 状态压缩dp/sgu 131 Hardwood floor
- SGU 131 贴地砖类型 状态压缩DP
- SGU 131 Hardwood floor(状态压缩dp)
- SGU-131--Hardwood floor--状态压缩DP
- SGU131 - Hardwood floor(状态压缩DP)
- SGU131 状态压缩~覆盖方案数
- SGU-223 Little Kings 状态压缩+DP
- SGU 396 Dance it up! 状态压缩dp
- sgu 225 Little Knights 状态压缩dp
- SGU132 - Another Chocolate Maniac(状态压缩DP)
- SGU 132 一道很恶心的状态压缩dp
- SGU 131.Hardwood floor 状态压缩DP
- sgu 223 - Little Kings 状态压缩DP
- Hardwood floor - SGU 131(状态压缩)
- SGU 132 Another Chocolate Maniac 状态压缩DP
- SGU223 -状态压缩DP
- SGU - 131 Hardwood floor (状态压缩)
- sgu 222 - Little Rooks 简单的状态压缩DP