当前位置:网站首页>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;
}
边栏推荐
- Miscellaneous records of Finance
- Study notes Minio
- The influence of the number of non-zero values in the picture on Classification
- Wechat push - template message parameter configuration
- JVM judges that the object is dead, and practices verify GC recycling
- 如何创建一个带诊断工具的.NET镜像
- 最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
- The second method of calculating overlapping integral
- 背包模型 AcWing 1024. 装箱问题
- SQL Server2000 database error
猜你喜欢

背包模型 AcWing 1024. 装箱问题

Analysis of C language pointer function and function pointer

发动机悬置系统冲击仿真-瞬时模态动态分析与响应谱分析

c语言指针函数和函数指针的辨析

The difference of iteration number and information entropy

The open source project Taier version 1.1 was officially released, and the list of new functions is fast

Internal and external troubles of digital collection NFT "boring ape" bayc

Longest ascending subsequence model acwing 482. Chorus formation

Play with the cluster configuration center and learn about the Taier console

IMG SRC is empty or SRC does not exist, and the picture has a white border
随机推荐
Take you hand-in-hand to develop a complete classic game [Tetris] from scratch, with less than 200 lines of logic.
背包模型 AcWing 423. 采药
十年架构五年生活-07 年轻气盛的蜕变
Chunjun supports DDL conversion and automatic execution of heterogeneous data sources - dtmo 02 review (including course playback + courseware)
IO流_字符流、IO流小结、IO流案例总结
2022牛客多校训练(3)A-Ancestor 题目翻译
SQL Server2000数据库错误
What is the issuing price of NFT (Interpretation of NFT and establishment of NFT world outlook)
What is the mystery of the gate of the meta universe?
Openatom openharmony sub forum, see you today at 14:00! Wonderful release of memorabilia attached
TensorFlow张量运算函数集
Digital triangle model acwing 275. pass note
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
最短移动距离和形态复合体的熵
Research on synaesthesia integration and its challenges
Sorry, you guys have something to deal with in the bank recently, which has been delayed
Derivation of the detailed expansion sto overlap integrals
NFT leaderboard -nft real offer latest address: NFT leaderboard.com
The open source project Taier version 1.1 was officially released, and the list of new functions is fast
Tree data conversion