洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 状压动归
考场上空间开大了一倍就爆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;
}
洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 状压动归的更多相关文章
- 洛谷 P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 解题报告
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题意: 给定一个长\(N\)的序列,求满足任意两个相邻元素之间的绝对值之差不超过\(K\)的这个序列的排列有多少个? 范围: ...
- 洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a u ...
- 洛谷 P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a u ...
- 洛谷 2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
一道水状压,然而不知道是不是太久没做过dp了,我盯着它二十分钟才反应过来.... 还把数组开小了WA了一发QAQ //Twenty #include<algorithm> #include ...
- P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 约翰家有N头奶牛,第i头奶牛的编号是Si,每头奶牛的编号都是唯一的.这些奶牛最近 在闹脾气,为表达不满的情绪,她们在挤奶的时候一定要排成混乱的队伍.在一只混乱的队 伍中,相邻奶牛的编号之差均 ...
- luogu P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- 洛谷 P2915 【[USACO08NOV]奶牛混合起来Mixed Up Cows】
类似于n皇后的思想,只要把dfs表示放置情况的数字压缩成一个整数,就能实现记忆化搜索了. 一些有关集合的操作: {i}在集合S内:S&(1<<i)==1: 将{i}加入集合S:S= ...
- [USACO08NOV]奶牛混合起来Mixed Up Cows(状态压缩DP)
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
随机推荐
- 铁大FaceBook的使用体验
铁大FaceBook是一个类似QQ和微信等聊天程序的缩小版网站,并且其针对领域较为狭窄:即只针对校园的学生和导员等人员.但其有值得推广的潜力性和可能性. 对于使用它的体验:第一点我感觉这个网站的界面很 ...
- jenkins 打包 springboot
遇到的坑 jdk maven 可以自己配置 也可以让jenkins生成 jenkins创建的项目打的包在 /var/lib/jenkins/jobs/ 需要手动去下载pom中的jar 吧pom复 ...
- Python编程:从入门到实践 - matplotlib篇 - Random Flow
随机漫游 # random_flow.py 随机漫游 import random class RandomFlow(): """一个生成随机漫游数据的类"&qu ...
- Adnroid_sdk安装代理
- ZOJ 3888 Twelves Monkeys
Twelves Monkeys Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Origina ...
- js区分ie不同版本
方法1 js中 if(window.ActiveXObject)//判断浏览器是否属于IE { var browser=navigator.appName var b_version=navigat ...
- spring中的单例和多例
单例 对象在整个系统中只有一份,所有的请求都用一个对象来处理,如service和dao层的对象一般是单例的. 为什么使用单例:因为没有必要每个请求都新建一个对象的时候,浪费CPU和内存. 多例 对象在 ...
- Oracle-查看用户对象信息
--视图(可查看拥有者.对象名称.创建时间.上次修改时间) SELECT t.OBJECT_NAME, t.CREATED, t.LAST_DDL_TIME FROM user_objects t o ...
- POJ 3709
简单的单调队列优化,注意是哪些点加入队列即可. #include <iostream> #include <cstdio> #include <algorithm> ...
- [HTML5] Accessibility Implementation for complex component
When you developing a complex component by your own, one thing you cannot ignore is Accessibility. C ...