当前位置:网站首页>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;
}
边栏推荐
- MAE
- IP production stream is so close to me
- Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
- 【LeetCode】4. Best time to buy and sell stock
- JS regular case-
- 一个实习生的CnosDB之旅
- the installer has encountered an unexpected error installing this package
- [at] ABC 258g - triple Reach - violence
- 【LeetCode】3. Merge two sorted lists · merge two ordered linked lists
- [at] ABC 258g - Triangle triples reachable - violence
猜你喜欢
多旅行商问题——公式和求解过程概述
EtherCAT state machine transition (ESM)
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Pat class a 1028 list sorting
Free use until 2015 -- viz artist multi touch plug-in package
How to configure GDAL under idea
Zohocrm deluge function application time verification
haproxy+keepalived搭建01
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
Project experience sharing: handwritten Chinese character recognition based on Shengsi mindspire
随机推荐
Worldview satellite remote sensing image data / meter resolution remote sensing image
How to configure GDAL under idea
在浏览器输入url后执行什么
【LeetCode】4. Best time to buy and sell stock
Are you still watching the weather forecast on TV?
The general trend of data news releases the power of visual reporting ----- essays after reading
方正锐利重磅升级到12.0版本,包装印前处理更加便捷、高效!
Product creation and commercial realization of chat robot (according to La Ma Bang - Dr. Wang Jingjing - speech)
HDMI2.1与HDMI2.0的区别以及转换PD信号。
Unity performance optimization
How to clear the console password for s7700 device
【cocos creator】点击按钮切换界面
Pat class a 1031 Hello world for u
什麼是定義?什麼是聲明?它們有何區別?
Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation
Enter three times and guess a number
Clip Related Script
微软安全响应中心
YOLO系列 --- xml2txt脚本
haproxy+keepalived集群搭建02