洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 状压动归
2024-08-31 11:48:35
考场上空间开大了一倍就爆0了QAQ…
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 21;
int height[30], pos[30];
long long dp[1 << maxn][21];
int main()
{
int n, delta;
scanf("%d%d",&n,&delta);
for(int i = 1;i <= n + 1; ++i) pos[i] = (1 << (i - 1)) ;
for(int i = 1;i <= n; ++i) scanf("%d",&height[i]);
for(int i = 1;i <= n; ++i) dp[pos[i]][i] = 1;
for(int i = 1;i < pos[n + 1]; ++i)
{
for(int j = 1;j <= n; ++j)
{
if((i & pos[j]) == 0) continue;
int mx = i ^ pos[j];
if(mx == 0) continue;
for(int k = 1;k <= n; ++k)
{
if( (i & pos[k]) == 0 || k == j || abs(height[j] - height[k]) <= delta) continue;
dp[i][j] += dp[mx][k];
}
}
}
long long fin = 0;
for(int i = 1;i <= n; ++i) fin += dp[pos[n + 1] - 1][i];
printf("%lld",fin);
return 0;
}
最新文章
- CocoaPods被卡住:Updating local specs repositories
- 通过Iframe在A网站页面内嵌入空白页面的方式,跨域获取B网站的数据返回给A网站!
- Jquery生成树 ztree
- (原创)jQuery Media Plugin-jQuery的网页媒体播放器插件的使用心得
- Python学习-day1
- Dedesql数据库类详解
- UE4 VR 模式下全屏解决办法
- vs.net_2003 下载 虽然是老古董了,但还是很有用的。
- PHP 解压zip文件的函数封装
- linux查看硬件环境
- 《A First Course in Probability》-chaper7-极限定理-强大数定理
- 64位windows8的 IIS运行32位COM组件报错的解决
- WCF遇到Oracle问题
- ASP.NET交互Rest服务接口(Jquery的Get与Post方式)
- classname 就是在css上添加类,然后js的类名等于
- kotlin 语言入门指南一
- Head First设计模式之工厂模式
- cordova build android Command failed with exit code EACCES
- inception_v2版本《Rethinking the Inception Architecture for Computer Vision》(转载)
- linux 内存使用情况详解