当前位置:网站首页>Luogu p1896 non aggression
Luogu p1896 non aggression
2022-07-27 11:14:00 【ThXe】
Title Description
Topic link
stay N×N In my chessboard K A king , Keep them from attacking each other , How many layout plans are there . The king can attack it up, down, left and right , And a grid in the upper left, lower left, upper right and lower right directions , common 8 Lattice .
Input format
There is only one line , It contains two numbers N,K ( 1 <=N <=9, 0 <= K <= N * N)
Output format
The number of schemes obtained
#include<bits/stdc++.h>
using namespace std;
int sat[2000], siz[2000];//sat Legal status of a line siz How many kings are there in the current state
int cnt = 0;
int n, m;
long long f[10][2000][100] = {
0 };//f[i][j][k] The first i That's ok Status as j discharge k Number of King's schemes
void dfs(int Sta, int now_size, int i_th)// Preprocess each state Sta Represents the state 00000 now_size Represents how many kings there are now i_th Represents which column of grid is currently in use
{
if (i_th >= n)// If it's done ( Note that it is greater than or equal to )
{
sat[++cnt] = Sta;// To deal with the first cnt Status
siz[cnt] = now_size;// The first cnt The number of kings that can be put in a state is now_size individual
return;// Create a new status
}
dfs(Sta, now_size, i_th + 1);// No, No i_th Lattice
dfs(Sta + (1 << i_th), now_size + 1, i_th + 2);// Use the first i_th Lattice , here i_th To add 2, That is to skip the next grid Because left and right cannot be adjacent
}
int main()
{
scanf("%d%d", &n, &m);
dfs(0, 0, 0);
for (int i = 1; i <= cnt; i++)f[1][i][siz[i]] = 1;// All States of the first layer are 1 In one case
for (int i = 2; i <= n; i++)
for (int j = 1; j <= cnt; j++)// The status of the upper layer is j
for (int k = 1; k <= cnt; k++)// The status of the current layer is k
{
if (sat[j] & sat[k])continue;// Up and down
if ((sat[j] << 1) & sat[k])continue;// Adjacent to the top right
if (sat[j] & (sat[k] << 1))continue;// Upper left adjacent
for (int s = m; s >= siz[j]; s--)f[i][j][s] += f[i - 1][k][s - siz[j]];// enumeration s, Calculation f[i][j][s]
}
long long ans = 0;
for (int i = 1; i <= cnt; i++)ans += f[n][i][m];// Count the final answer , Remember to use long long
printf("%lld", ans);
return 0;
}
边栏推荐
- tensorflow运行报错解决方法
- img src为空或者src不存在,图片出现白色边框
- Opengauss kernel analysis - statistics and row count estimation
- parsel的使用
- Ten year structure five year life-07 young and vigorous transformation
- Background color style modification on table hover in antd
- How to assemble a registry
- c语言指针函数和函数指针的辨析
- Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
- TensorFlow张量运算函数集
猜你喜欢
随机推荐
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
Wechat push - template message parameter configuration
熵与形态的非递进现象
Based on the open source stream batch integrated data synchronization engine Chunjun data restore DDL parsing module actual combat sharing
JVM judges that the object is dead, and practices verify GC recycling
8 find subsequences with a maximum length of K
4 search insertion location
GEE中下载过程中出现 Error: Image.clipToBoundsAndScale, argument 'input'
Wilderness search --- search iterations
Today's code farmer girl summarized her notes about NPM package management and URL module
学习笔记-minio
最长上升子序列模型 AcWing 1014. 登山
Instructions for mock platform
神经网络学习笔记
Longest ascending subsequence model acwing 1012. Sister Cities
Taishan Office Technology Lecture: scaling and opening files
最长上升子序列模型 AcWing 1010. 拦截导弹
What is the mystery of the gate of the meta universe?
6 find the smallest letter larger than the target letter
The second method of calculating overlapping integral








