sgu223:Little Kings(状压DP)
来源:互联网 发布:埃菲尔铁塔数据 编辑:程序博客网 时间:2024/04/29 06:10
题目大意:
分析:
AC code:
#include <cstdio>#include <cstring>#include <iostream>typedef long long LL;#define get(s, i) ((s>>(i-1))&1)#define ONLINE_JUDGEconst int MAXN = 10, MAXK = 109;int n, k;int sta[1<<MAXN], tot, Map[1<<MAXN];LL f[2][MAXK][1<<MAXN];LL ans;void dfs(int g, int s, int now, int fl, int sum){ if(now == n+1) { for(int i = 0; i+sum <= k; ++i) f[fl][i+sum][Map[s]] += f[fl^1][i][Map[g]]; return ; } dfs(g, s, now+1, fl, sum); if(now > 1 && (get(s, now-1) || get(g, now-1))) return ; if(get(g, now)) return ; if(now < n && get(g, now+1)) return ; if(sum+1 > k) return ; dfs(g, s|(1<<(now-1)), now+1, fl, sum+1);}bool check(int s){ for(int i = 2; (1<<(i-1)) <= s; ++i) if(get(s, i-1) && get(s, i)) return false; return true;}int main(){ #ifndef ONLINE_JUDGE freopen("sgu223.in", "r", stdin); freopen("sgu223.out", "w", stdout); #endif std::ios::sync_with_stdio(0); std::cin >> n >> k; for(int i = 0; i < (1<<n); ++i) if(check(i)) sta[++tot] = i, Map[i] = tot; f[0][0][1] = 1; for(int i = 1; i <= n; ++i) { memset(f[i&1], 0, sizeof(f[i&1])); for(int j = 1; j <= tot; ++j) dfs(sta[j], 0, 1, i&1, 0); } for(int i = 1; i <= tot; ++i) ans += f[n&1][k][i]; std::cout << ans << std::endl; #ifndef ONLINE_JUDGE fclose(stdin); fclose(stdout); #endif return 0;}
0 0
- sgu223 Little Kings 状压DP
- sgu223:Little Kings(状压DP)
- [SGU 223]Little Kings(状压DP)
- SGU 223 Little Kings (状压dp)
- SGU 223 little kings BSOJ2772 状压DP
- SGU223(状压DP入门)
- sgu 223 Little Kings 状态压缩dp
- sgu 223 - Little Kings 状态压缩DP
- 【状压DP】【cofun1376】kings
- SGU223 -状态压缩DP
- SGU223 状态压缩DP
- SGU 223 Little Kings
- SGU 223 Little Kings
- SGU 223 Little Kings
- SGU 223 Little Kings
- sgu-223 Little Kings
- SGU 223 Little Kings
- SGU 223. Little Kings
- BZOJ 1486 最小圈
- POJ2349---Arctic Network
- IE-->使用X-UA-Compatible来设置IE浏览器兼容模式
- Docker简介
- Hello OpenGL——OpenGL在Visual c++6.0安装和配置
- sgu223:Little Kings(状压DP)
- 安装CocoaPods和使用
- mongoDB——自动分片介绍及简单实现
- mongoDB——副本集
- [POJ3614]Sunscreen[贪心][优先队列]
- 学习mongoDB的一些感受
- android手机计算器
- 黑马程序员——java---IO(一)
- JAVA SSH 框架介绍