当前位置:网站首页>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;
}
边栏推荐
- Influence of black and white pixel distribution on iteration times
- Thank you for your likes and attention
- 推导STO双中心动能积分的详细展开式
- 泰山OFFICE技术讲座:缩放比例与打开文件
- I've compromised. Since everyone wants to call me Yelin, there's nothing I can do
- antd中table hover上去的背景色样式修改
- Yum source installation
- 如何创建一个带诊断工具的.NET镜像
- Application scenarios, key technologies and network architecture of communication perception integration
- Neural network learning notes
猜你喜欢

Asustek unparalleled, this may be the best affordable high brush thin notebook on the screen
![Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.](/img/7f/f42f9267cdff35522c260ef073bab9.png)
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.

栈 AcWing 3302. 表达式求值

Knapsack model acwing 423. Picking herbs

Local and overall differences between emergence and morphology

Analysis of C language pointer function and function pointer

熵与形态的非递进现象

15 design movie rental system

Wilderness search --- search iterations

properties文件
随机推荐
Sort th in antd table to prevent hovering color change +table hovering row color change +table header color change
背包模型 AcWing 1022. 宠物小精灵之收服
背包模型 AcWing 1024. 装箱问题
7 row K with the weakest combat effectiveness in the matrix
Derive the detailed expansion of STO double center kinetic energy integral
对象数组去重
十年架构五年生活-07 年轻气盛的蜕变
8 find subsequences with a maximum length of K
背包模型 AcWing 423. 采药
IO stream_ Character stream, IO stream summary, IO stream case summary
The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
How to create a.Net image with diagnostic tools
背包问题 AcWing 9. 分组背包问题
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
计算重叠积分的第二种方法
Wilderness search --- search iterations
10 complete half of the questions
The article will not keep VIP charges all the time. It will be open for a period of time
Instructions for mock platform