当前位置:网站首页>P2704 [noi2001] artillery position (shape pressure DP)
P2704 [noi2001] artillery position (shape pressure DP)
2022-07-03 07:58:00 【eva_ can(not)survive】
[NOI2001] Artillery position - Luogu https://www.luogu.com.cn/problem/P2704 Today is the pressure of learning dp A day of !
The data range of this question is obvious, which can be used to press dp To write , You should think of it when you get started dp There are two dimensions in the array i Xing He i The state of the line , But the influence of artillery has two lines , So we need to record the status of the previous line .
You can calculate the number of feasible schemes in each line before enumerating , It can save time , Some questions may get stuck .
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <cmath>
#include <map>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int MN = 65005;
const int MAXN = 1e6 + 10;
const int INF = 0x3f3f3f3f;
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) ((x)&(-x))
using P = pair<int, int>;
int n, m;
int a[MAXN];
int dp[(1 << 10)][(1 << 10)][105];
int cnt;
int rec[MAXN];
int sum[MAXN];
int getsum(int x) {
int tot = 0;
while (x)
tot++, x -= lowbit(x);
return tot;
}
int main() {
char ch;
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf(" %c", &ch);
a[i] <<= 1;
a[i] += ((ch == 'H') ? 1 : 0);
}
}
rec[++cnt] = 0;
for (int i = 1; i < (1 << m); i++) {
if (i & (i << 1))
continue;
if (i & (i << 2))
continue;
rec[++cnt] = i;
}
for (int i = 1; i <= cnt; i++) {
sum[i] = getsum(rec[i]);
}
for (int i = 1; i <= cnt; i++) {
if (rec[i]&a[1])
continue;
dp[0][rec[i]][1] = sum[i];
}
for (int i = 1; i <= cnt; i++) {
if (rec[i]&a[2])
continue;
for (int j = 1; j <= cnt; j++) {
if (rec[i]&rec[j] || rec[j]&a[1])
continue;
dp[rec[j]][rec[i]][2] = sum[i] + sum[j];
}
}
for (int i = 3; i <= n; i++) {
for (int j = 1; j <= cnt; j++) {
if (rec[j]&a[i])
continue;
for (int k = 1; k <= cnt; k++) {
if (rec[k]&rec[j] || rec[k]&a[i - 1])
continue;
for (int p = 1; p <= cnt; p++) {
if (rec[p]&rec[k]||rec[p]&rec[j] || rec[p]&a[i - 2])
continue;
dp[rec[k]][rec[j]][i] = max(dp[rec[k]][rec[j]][i], dp[rec[p]][rec[k]][i - 1] + sum[j]);
}
}
}
}
int ans = 0;
for (int i = 1; i <= cnt; i++) {
if (rec[i]&a[n])
continue;
for (int j = 1; j <= cnt; j++) {
if (rec[i]&rec[j] || rec[j]&a[n - 1])
continue;
ans = max(ans, dp[rec[j]][rec[i]][n]);
}
}
printf("%d", ans);
return 0;
}
边栏推荐
- What is a data type? What is the use of data types?
- Go language - loop statement
- PDO and SDO concepts
- unity2019_ Input management
- Unity2019_ Natural ambient light_ Sky box
- RM delete file
- My touch screen production "brief history" 2
- [at] abc 258G - Triangle 三元組可達-暴力
- 使用 FileChannel 进行文件的复制拷贝
- Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“
猜你喜欢

JS common basic case sorting (continuous update)
![[MySQL 12] MySQL 8.0.18 reinitialization](/img/e1/9874df18bbc8d80c3c5c5fe39aefc9.png)
[MySQL 12] MySQL 8.0.18 reinitialization

the installer has encountered an unexpected error installing this package

OSPF experiment

方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!

Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“
![[step on the pit series] MySQL failed to modify the root password](/img/d0/f975baf18bac506208abff3713ac03.png)
[step on the pit series] MySQL failed to modify the root password

Pat class a 1028 list sorting

Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does

My touch screen production "brief history" 1
随机推荐
Pat grade a 1027 colors in Mars
Quelle est la définition? Qu'est - ce qu'une déclaration? Quelle est la différence?
Microsoft Security Response Center
jsutlis
Uniapp learning records
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
MAE
Redis批量启停脚本
MaxCompute字符串分割函数-SPLIT_PART
YOLO系列 --- xml2txt脚本
PDO and SDO concepts
一条通往服务器所有端口的隧道
Huawei switch: configure Telnet, SSH and web access
Screenshot tool snipaste
PHP wechat red packet grabbing algorithm
多旅行商问题——公式和求解过程概述
PHP常用排序算法
Retail philosophy retail psychological warfare after reading -- 7-11 is a good product!
华为交换机配置ssh登录远程管理交换机
Huawei s5700 switch initialization and configuration Telnet, SSH user methods