当前位置:网站首页>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;
}
边栏推荐
- C language 2: find the maximum value of three numbers, find the middle value of three numbers, and write program steps
- Overview of data security in fog computing
- The article will not keep VIP charges all the time. It will be open for a period of time
- Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
- IO stream_ Character stream, IO stream summary, IO stream case summary
- IO流_字符流、IO流小结、IO流案例总结
- parsel的使用
- TensorFlow张量运算函数集
- Ten year structure five year life-07 young and vigorous transformation
- 迭代次数的差异与信息熵
猜你喜欢

Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?

Use of beautifulsoup

最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼

Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source

SQL Server2000数据库错误

Use of pyquery

Local and overall differences between emergence and morphology

How to build a real-time development platform to deeply release the value of enterprise real-time data?

The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd

Influence of black and white pixel distribution on iteration times
随机推荐
SQL Server2000 database error
01 BTC cryptology principle
Sorry, you guys have something to deal with in the bank recently, which has been delayed
Chengying, kangaroo cloud one-stop fully automated operation and maintenance steward, is officially open source
Play with the cluster configuration center and learn about the Taier console
pyquery 的使用
深析C语言的灵魂 -- 指针
Application of 5g private network in smart medicine
中国剩余定理 AcWing 204. 表达整数的奇怪方式
The second method of calculating overlapping integral
Ten year structure five year life-07 young and vigorous transformation
ACM warm-up Exercise 2 in 2022 summer vacation (summary)
Self optimization of wireless cell load balancing based on machine learning technology
背包问题 AcWing 9. 分组背包问题
洛谷P1441 砝码称重
Taishan Office Technology Lecture: scaling and opening files
Synaesthesia integrated de cellular super large-scale MIMO and high-frequency wireless access technology
最长上升子序列模型 AcWing 482. 合唱队形
洛谷 P3052 [USACO12MAR]Cows in a Skyscraper G
TensorFlow张量运算函数集