当前位置:网站首页>P1896 [scoi2005] non aggression (shape pressure DP)
P1896 [scoi2005] non aggression (shape pressure DP)
2022-07-03 07:58:00 【eva_ can(not)survive】
[SCOI2005] Don't invade each other - Luogu https://www.luogu.com.cn/problem/P1896 Elementary pressure dp, I learned a lot after reading the first solution , First of all, the compression of a matrix can start with rows , Record the status in the current line , First, let's look at this topic and think about 3 Status , Place of action , Current row status and number of Kings . So we need to think about the recurrence equation as f[i][j][k](i For the current line ,j In this line ,k For the number of Kings )+=f[i-1][s][k-t](s Is the status of the previous line ,t For the number of kings in this line )
So we have to deal with the possible states in a line and the number of kings in the changed state in advance , So the second dimension can be optimized as the number of this state , This also solves the number of kings in a row ,( I really learned a lot after reading the solution , Before, I foolishly thought that I would put the state directly on the second dimension of the array , It's easy to explode ,orz bosses )
Then we have to judge the transfer conditions
s&j when It means that up and down can attack
s<<1&j Attack from the bottom left to the top right
j<<1&s Attack from top left to bottom right
Then you can be happy code 了
#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 sit[2000], gs[2000];
int cnt = 0;
int n, yong;
ll f[10][2000][100];
void dfs(int he, int sum, int node) {
if (node >= n) {
sit[++cnt] = he;
gs[cnt] = sum;
return;
}
dfs(he, sum, node + 1);
dfs(he + (1 << node), sum + 1, node + 2);
}
int main() {
scanf("%d %d", &n, &yong);
dfs(0, 0, 0);
for (int i = 1; i <= cnt; i++)
f[1][i][gs[i]] = 1;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= cnt; j++) {
for (int k = 1; k <= cnt; k++) {
if (sit[j]&sit[k])
continue;
if ((sit[j] << 1)&sit[k])
continue;
if (sit[j] & (sit[k] << 1))
continue;
for (int s = yong; s >= gs[j]; s--)
f[i][j][s] += f[i - 1][k][s - gs[j]];
}
}
}
ll ans = 0;
for (int i = 1; i <= cnt; i++) {
ans += f[n][i][yong];
}
printf("%lld\n", ans);
return 0;
}边栏推荐
- Go language - loop statement
- Quality blog——
- 什么是定义?什么是声明?它们有何区别?
- PHP common sorting algorithm
- [cocos creator] Click the button to switch the interface
- Open the influence list of "National Meteorological Short Videos (Kwai, Tiktok) in November" in an interactive way“
- Static keyword
- VMware virtual machine configuration static IP
- Pat class a 1031 Hello world for u
- WPF:解决MaterialDesign:DialogHost 无法关闭问题
猜你喜欢

Unity XR realizes interaction (grasping, moving, rotating, transmitting, shooting) -pico

LwIP learning socket (application)

haproxy+keepalived集群搭建02

Research shows that breast cancer cells are more likely to enter the blood when patients sleep

Unity2019_ Natural ambient light_ Sky box

Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task

My touch screen production "brief history" 1

*p++、*++p、++*p、(*p)++
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

Lua framwrok framework starts
随机推荐
WPF:解决MaterialDesign:DialogHost 无法关闭问题
Unity dotween sequence animation replay problem.
Huawei switch console password reset, device initialization, default password
链式长取值
Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
unity2019_ Input management
【cocos creator】点击按钮切换界面
Idea unreference Display Effect
Install cross compiler arm none liunx gnueabihf
创业团队如何落地敏捷测试,提升质量效能?丨声网开发者创业讲堂 Vol.03
regular expression
s7700设备如何清除console密码
[MySQL 14] use dbeaver tool to remotely backup and restore MySQL database (Linux Environment)
C language learning notes (mind map)
优质博客——
*p++、*++p、++*p、(*p)++
Client server model
Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)
Huawei switch basic configuration (telnet/ssh login)
Usage of (case, when) in PostgreSQL