sgu223
来源:互联网 发布:石家庄软件开发培训 编辑:程序博客网 时间:2024/06/04 18:21
状态压缩
复杂度:
#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>#include<algorithm>const int maxn = 15, maxk = 105, sz = 10;struct Trans{ int fr,to,imp; Trans(int fr = 0,int to = 0,int imp = 0):fr(fr),to(to),imp(imp){}};int n, k;Trans ts[1<<(sz<<1)]; int tl;long long f[maxn][maxk][1<<sz], ans;void DFS(int col,int last,int now,int cnt){ if(col == n) ts[++tl] = Trans(last,now,cnt); else { DFS(col + 1, last, now, cnt); if(!col || (!(last&(1<<(col-1))) && !(now&(1<<(col-1))))) { DFS(col + 1, last|(1<<col), now, cnt); DFS(col + 1, last, now|(1<<col), cnt + 1); } }}int main(){ #ifndef ONLINE_JUDGE freopen("sgu223.in","r",stdin); freopen("sgu223.out","w",stdout);#endif std::cin >> n >> k; f[0][0][0] = 1; DFS(0,0,0,0); for(int i = 1; i <= n; i++) for(int j = 0; j <= k; j++) for(int p = 1; p <= tl; p++) if(j - ts[p].imp >= 0) f[i][j][ts[p].to] += f[i-1][j-ts[p].imp][ts[p].fr]; for(int i = 0; i < (1<<n); i++) ans += f[n][k][i]; std::cout << ans; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout);#endif return 0;}
0 0
- sgu223
- sgu223
- SGU223 -状态压缩DP
- SGU223 状态压缩DP
- sgu223 Little Kings 状压DP
- sgu223:Little Kings(状压DP)
- SGU223(状压DP入门)
- UVA1407
- 随机生成6位验证码或密码(字母和数字组合)
- js中substr和substring两个方法的区别
- 生产者、消费者问题,python实现
- Redis3.0集群部署文档(centos系统)
- sgu223
- iOS7开发注意事项
- ios6、7 版本适配
- ExtJs 入门教程
- 15年滨州学院CSDN高校俱乐部第二届编程比赛
- Google Protocol Buffers和java字符串处理对比
- Android程序崩溃统一处理机制
- ViewPager 详解(一)---基本入门
- iOS 推送处理