当前位置:网站首页>彩虹(状压dp)
彩虹(状压dp)
2022-04-21 06:21:00 【Bzdhxs_nt】
思路
经典状压 d p dp dp
用 [ 0 , 7 m ) [0,7^m) [0,7m) 来表示状态每列的涂色状态
注意判断相邻同色的方法!
代码
int qmi(int a,int b){
int res =1;
while(b){
if(b&1) res = res*a;
a = a*a;
b >>= 1;
}
return res;
}
int n,m;
vector<int> state;
bool check(int x){
int s = x/7,yu = x%7;
int len = n;
int f = 0;
while(--len){
if((s%7) == yu){
f = 1;
break;
}
yu = s%7, s /= 7;
}
if(!f) return true;
return false;
}
bool judge(int l,int r){
int len = n;
int st1 = state[l];
int st2 = state[r];
int s,t;
while(len--){
s=st1%7,t=st2%7;
if(s==t) return false;
st1/=7,st2/=7;
}
return true;
}
int f[11][100005];
signed main()
{
cin >> n >> m;
int sta = qmi(7,n);
vector<int> get[sta];
forr(i,0,sta-1){
if(check(i)) state.push_back(i);
}
for(int i = 0 ; i < state.size();i++)
for(int j = 0; j < state.size();j++)
if(judge(i,j)) get[i].push_back(j);
for(int i = 0;i < state.size();i++) f[1][i] = 1;
forr(i,2,m){
for(int j = 0;j < state.size();j++){
for(auto k:get[j]){
f[i][j] = (f[i][j]+f[i-1][k]) %mod;
}
}
}
int ans = 0;
for(int i = 0;i < state.size();i++){
ans = (ans+f[m][i])%mod;
}
cout << ans << endl;
return 0;
}
版权声明
本文为[Bzdhxs_nt]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51687628/article/details/124243469
边栏推荐
- TensorFlow
- 完全清理mysql-win
- 跨域问题-Allow-Origin header contains multiple values... but only one is allowed
- Add parentheses to Boolean expressions for short circuit operators
- Notes on the use of STM32 h743 ECC memory
- 用JS函數形式實現一個Array.prototype.forEach(),.map(),.filter()
- STM32 H743 ECC内存相关使用说明笔记
- 导jstl标签库uri没有提示
- 登录页面讲解
- Gojs anhydrous printing plate
猜你喜欢
随机推荐
Summary of differences between MySQL and Oracle
【LeetCode 6】Z 字形变换
Learn SCI paper drawing skills (c)
【LeetCode 459 】重复的子字符串
杂项1
平面半交板子
C# 基础
2020杭电多校赛第一场1006 Finding a MEX(hdu6756)
格式检查工具eslint
微信小程序request封装
做一款自己的小程序
学习笔记-最长子序列,最大子方块
【WPF】笔记
[STM32] cubemx configuration diagram of 480mhz clock under 25MHz external crystal oscillator of h743
如何实现一个线程池隔离?
2020牛客暑期多校训练营第二场 I Interval题解
D. 388535
力扣-322.零钱兑换
Li Kou video note 21 - depth first search method + 938 question method
Pm2 部署 Nuxt 项目





![[LabVIEW] record some pits in LabVIEW project](/img/88/5556dd887d54f11bbc3afc9dfce25e.png)


