当前位置:网站首页>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;
}边栏推荐
- Huawei switch console password reset, device initialization, default password
- Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
- Harmonyos third training notes
- [end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
- register关键字
- PostGIS space function
- [cocos creator] get the resource UUID
- Redis batch startup and shutdown script
- Wechat applet taro learning record
- Ilruntime learning - start from scratch
猜你喜欢
![[untitled]](/img/3d/27a7229e3f0ccf0ca5ae1f00a92513.jpg)
[untitled]

Wechat applet taro learning record

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

haproxy+keepalived集群搭建02

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

Pulitzer Prize in the field of information graphics - malofiej Award

PostGIS space function

Ventuz Foundation Series "one step at the door"

Iterm2 setting

WPF:解决MaterialDesign:DialogHost 无法关闭问题
随机推荐
What is a data type? What is the use of data types?
I want to do large screen data visualization application feature analysis
Lua framwrok framework starts
Technical dry goods | thinking about the unification of dynamic and static diagrams of AI framework
WorldView卫星遥感影像数据/米级分辨率遥感影像
Worldview satellite remote sensing image data / meter resolution remote sensing image
链式长取值
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
An article for you to understand - Manchester code
Pulitzer Prize in the field of information graphics - malofiej Award
tp3.2和tp5.0的区别
Huawei s5700 switch initialization and configuration SSH and telnet remote login methods
[USACO12MAR]Cows in a Skyscraper G(状态压缩dp)
Pycharm remote ssh pyenv error: pydev debugger: warning: trying to add breakpoint to file that does
P1896 [SCOI2005] 互不侵犯(状压dp)
P2704 [NOI2001] 炮兵阵地(状压dp)
[untitled]
Are you still watching the weather forecast on TV?
Pat class a 1028 list sorting
Zohocrm deluge function application time verification