当前位置:网站首页>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;
}边栏推荐
- I want to do large screen data visualization application feature analysis
- How does yarn link help developers debug NPM packages?
- Precautions for opensips and TLS SIP trunk docking
- What to do after the browser enters the URL
- 什么是数据类型?数据类型有什么用?
- Viz artist advanced script video tutorial -- stringmap use and vertex operation
- Pat class a 1028 list sorting
- 【cocos creator】点击按钮切换界面
- Unity2019_ Lighting system
- JS common basic case sorting (continuous update)
猜你喜欢

一篇文章让你读懂-曼彻斯特编码

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

Technical dry goods | Bert model for the migration of mindspore NLP model - text matching task (2): training and evaluation

My touch screen production "brief history" 1

Harmonyos third training notes

How to configure GDAL under idea

Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico

Screenshot tool snipaste

freetype库的移植

WPF:解决MaterialDesign:DialogHost 无法关闭问题
随机推荐
Ventuz Foundation Series "one step at the door"
【LeetCode】3. Merge two sorted lists · merge two ordered linked lists
What is a data type? What is the use of data types?
VMware virtual machine configuration static IP
Client server model
Unity XR实现交互(抓取,移动旋转,传送,射击)-Pico
使用 FileChannel 进行文件的复制拷贝
Go language - loop statement
2020-12-12
[global product discovery 2] the first pure cloud augmented reality (AR) platform - Israel
An intern's journey to cnosdb
What is definition? What is a statement? What is the difference between them?
Unity2019_ Natural ambient light_ Sky box
Clip Related Script
I want to do large screen data visualization application feature analysis
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
Structure of golang
Pat class a 1030 travel plan
Pat grade a 1027 colors in Mars
Pulitzer Prize in the field of information graphics - malofiej Award