当前位置:网站首页>[acwing 1064 little king] shaped pressure DP
[acwing 1064 little king] shaped pressure DP
2022-07-28 03:12:00 【Yuzhibo one dozen seven~】
Topic link
The question
You need to be in a n*n Put your chessboard k A chess piece , Make them not attack each other , Every king will treat his neighbor 8 Location attack , Now, how many placement schemes do you have
Ideas
The amount of data is 10, Obvious pressure dp topic ,f[i][j][k] It represents the front i-1 That's ok , Now the first i The row status is j, The total number of pieces is k Number of alternatives , We can preprocess every legal state in advance , And every state that can be transferred can also be preprocessed , Then there is the pressure dp Part of , There is one thing to note , It is to judge the left shift and right shift during state transition preprocessing , Originally, I wrote only shift left , It is found that the answer is larger than the standard answer , The state that can be transferred during pretreatment increases , Therefore, it is correct to add a shift right judgment , Now look at the code :
#include<bits/stdc++.h>
using namespace std;
const int N = 12;
vector<long long> hefa;
vector<long long> zhuanyi[1<<N];
long long f[N][1<<N][N*N],cnt[1<<N];
int count(int x){
int ans = 0;
while(x) ans += (x&1),x >>= 1;
return ans;
}
int main(){
int n,k;
cin>>n>>k;
zhuanyi[0].push_back(0);
for(int i=0;i<(1<<n);i++){
if((i&(i>>1)) == 0) hefa.push_back(i);
cnt[i] = count(i);
}
f[0][0][0] = 1;
for(int i=0;i<hefa.size();i++){
for(int j=i+1;j<hefa.size();j++){
long long x = hefa[i],y = hefa[j];
if(((x>>1)&(y)) == 0 && (x&y) == 0 && (x&(y>>1)) == 0) zhuanyi[x].push_back(y),zhuanyi[y].push_back(x);
// This is the place , Judge at the same time (x>>1)&(y) == 0 and (x&(y>>1)) == 0, Or you'll make a mistake
}
}
// for(int i=0;i<hefa.size();i++){
// cout<<hefa[i]<<' ';
// for(auto t : zhuanyi[hefa[i]]) cout<<t<<' ';
// cout<<endl;
// }
long long ans = 0;
for(int i=1;i<=n;i++){
for(int s=0;s<=k;s++)
for(auto x : hefa){
for(auto y : zhuanyi[x]){
if(s >= cnt[x])
f[i][x][s] += f[i-1][y][s-cnt[x]];
}
}
}
for(auto t : hefa) ans += f[n][t][k];
cout<<ans<<endl;
return 0;
}
边栏推荐
- Unexpected harvest of epic distributed resources, from basic to advanced are full of dry goods, big guys are strong!
- 随机森林与集成方法学习笔记
- NPDP考生!7月31号考试要求在这里看!
- Trivy [1] tool scanning application
- MySQL essay
- Design of the multi live architecture in different places of the king glory mall
- 数据湖:各模块组件
- Skills in writing English IEEE papers
- 没法预测明天的涨跌
- R 笔记 MICE
猜你喜欢

Actual case of ROS communication

Why is it that when logging in, you clearly use the account information already in the database, but still display "user does not exist"?

"29 years old, general function test, how do I get five offers in a week?"

分布式 session 的4个解决方案,你觉得哪个最好?

QFileDevice、QFile、QSaveFile、QTemporaryFile

【2022 牛客第二场J题 Link with Arithmetic Progression】三分套三分/三分极值/线性方程拟合最小二乘法

exness:日本物价上涨收入下降,英镑/日元突破 165

行业洞察 | 语音识别真的超过人耳朵了吗?

CNN循环训练的解释 | PyTorch系列(二十二)

Docker advanced -redis cluster configuration in docker container
随机推荐
别再用 offset 和 limit 分页了,性能太差!
社恐适合什么工作?能做自媒体吗?
使用PyTorch的TensorBoard-可视化深度学习指标 | PyTorch系列(二十五)
ELS timer
[email protected] Annotation usage
Is the securities account given by qiniu safe? Can qiniu open an account and buy funds
Actual case of ROS communication
Is it you who are not suitable for learning programming?
JS event object offsetx/y clientx y pagex y
每日刷题巩固知识
Design of the multi live architecture in different places of the king glory mall
Note that these regions cannot take the NPDP exam in July
行业洞察 | 语音识别真的超过人耳朵了吗?
[ACNOI2022]总差一步
Commissioning experience of ROS
意外收获史诗级分布式资源,从基础到进阶都干货满满,大佬就是强!
基于JSP&Servlet实现的众筹平台系统
Promise object
Redis群集
牛客-TOP101-BM340