博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[POJ1185]炮兵阵地(状压DP)
阅读量:4592 次
发布时间:2019-06-09

本文共 2739 字,大约阅读时间需要 9 分钟。

题目链接:http://poj.org/problem?id=1185

这个和之前的不一样,在于某个点影响的范围是两格。那么dp(cur,pre,i)表示第i行状态为cur,i-1行状态为pre时可以有多少种放法。转移的时候枚举ppre,就是i-2行即可。照葫芦画瓢

1 /*  2 ━━━━━┒ギリギリ♂ eye!  3 ┓┏┓┏┓┃キリキリ♂ mind!  4 ┛┗┛┗┛┃\○/  5 ┓┏┓┏┓┃ /  6 ┛┗┛┗┛┃ノ)  7 ┓┏┓┏┓┃  8 ┛┗┛┗┛┃  9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include 
18 #include
19 #include
20 #include
21 #include
22 #include
23 #include
24 #include
25 #include
26 #include
27 #include
28 #include
29 #include
30 #include
31 #include
32 #include
33 #include
34 #include
35 using namespace std; 36 #define fr first 37 #define sc second 38 #define cl clear 39 #define BUG puts("here!!!") 40 #define W(a) while(a--) 41 #define pb(a) push_back(a) 42 #define Rint(a) scanf("%d", &a) 43 #define Rll(a) scanf("%I64d", &a) 44 #define Rs(a) scanf("%s", a) 45 #define Cin(a) cin >> a 46 #define FRead() freopen("in", "r", stdin) 47 #define FWrite() freopen("out", "w", stdout) 48 #define Rep(i, len) for(int i = 0; i < (len); i++) 49 #define For(i, a, len) for(int i = (a); i < (len); i++) 50 #define Cls(a) memset((a), 0, sizeof(a)) 51 #define Clr(a, x) memset((a), (x), sizeof(a)) 52 #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) 53 #define lrt rt << 1 54 #define rrt rt << 1 | 1 55 #define pi 3.14159265359 56 #define RT return 57 #define lowbit(x) x & (-x) 58 #define onecnt(x) __builtin_popcount(x) 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair
pii; 63 typedef pair
psi; 64 typedef pair
pll; 65 typedef map
msi; 66 typedef vector
vi; 67 typedef vector
vl; 68 typedef vector
vvl; 69 typedef vector
vb; 70 71 const int maxn = 101; 72 const int maxm = 11; 73 char tmp[maxm]; 74 int dp[1<
<
<< m; 90 For(i, 1, n+1) { 91 Rs(tmp); 92 for(int j = m - 1; j >= 0; j--) { 93 G[i] <<= 1; 94 G[i] |= (tmp[j] == 'P' ? 1 : 0); 95 } 96 } 97 Rep(i, mm) { if(!ok(i, 1)) continue; 98 dp[i][0][1] = __builtin_popcount(i); 99 }100 Rep(i, mm) { if(!ok(i, 1)) continue;101 Rep(j, mm) { if(!ok(j, 2)) continue;102 if(i & j) continue;103 dp[i][j][2] = max(dp[i][j][2], dp[i][0][1] + __builtin_popcount(i));104 }105 }106 For(i, 3, n+1) {107 Rep(cur, mm) { if(!ok(cur, i)) continue;108 Rep(pre, mm) { if(!ok(pre, i-1)) continue;109 if(cur & pre) continue;110 Rep(ppre, mm) {111 if((cur & pre) || (cur & ppre) || (pre & ppre)) continue;112 dp[cur][pre][i] = max(dp[cur][pre][i], dp[pre][ppre][i-1] + __builtin_popcount(cur));113 }114 }115 }116 }117 int ret = 0;118 Rep(i, mm) {119 Rep(j, mm) {120 ret = max(ret, dp[i][j][n]);121 }122 }123 printf("%d\n", ret);124 }125 RT 0;126 }

 

转载于:https://www.cnblogs.com/kirai/p/5877003.html

你可能感兴趣的文章
5. Longest Palindromic Substring (DP)
查看>>
sql语句一些简单的用法
查看>>
HDU 5934 Bomb(炸弹)
查看>>
领域驱动设计之聚合与聚合根实例一
查看>>
selenium中各个模块操作:下拉框、鼠标悬浮连贯、拼图拖拽操作
查看>>
C# 调用Windows图片查看器
查看>>
Excel系列教程(1):如何自动填充单元格
查看>>
jQuery中的冒泡事件和阻止冒泡
查看>>
pythonchallenge闯关 第13题
查看>>
linux上很方便的上传下载文件工具rz和sz使用介绍
查看>>
React之特点及常见用法
查看>>
【WEB前端经验之谈】时间一年半,或沉淀、或从零开始。
查看>>
优云软件助阵GOPS·2017全球运维大会北京站
查看>>
java23中设计模式只责任链模式
查看>>
linux 装mysql的方法和步骤
查看>>
poj3667(线段树区间合并&区间查询)
查看>>
51nod1241(连续上升子序列)
查看>>
SqlSerch 查找不到数据
查看>>
集合相关概念
查看>>
Memcache 统计分析!
查看>>