洛谷 2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
一道水状压,然而不知道是不是太久没做过dp了,我盯着它二十分钟才反应过来。。。。
还把数组开小了WA了一发QAQ
//Twenty
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#include<cmath>
#include<queue>
#include<ctime>
const int maxn=(1<<16)+2;
typedef long long LL;
using namespace std;
int n,kk,nn,cnt[maxn],id[17];
LL dp[2][maxn][16]; namespace fastIO {
const int sz=1<<15|1;
char ch,buf[sz],*l,*r;
void gechar(char &c) {
if(l==r) r=(l=buf)+fread(buf,1,sz,stdin);
c = l==r?(char)EOF:*l++;
}
template<typename T> void read(T &x) {
int f=1; x=0; gechar(ch);
while(ch!='-'&&(ch<'0'||ch>'9')) gechar(ch);
if(ch=='-') f=-1,gechar(ch);
for(;ch>='0'&&ch<='9';gechar(ch)) x=x*10+ch-'0'; x*=f;
}
} void pre() {
nn=(1<<n)-1;
for(int i=0;i<=nn;i++) {
int tp=i;
while(tp) {
cnt[i]++;
tp-=(tp&(-tp));
}
}
} void work() {
int o=0;
dp[o][0][0]=1;
id[0]=1e9;
LL ans=0;
for(int i=1;i<=n;i++) {
o^=1;
for(int j=1;j<=nn;j++) if(cnt[j]==i) {
for(int k=1;k<=n;k++) {
int fl=0;
if(j&(1<<k-1)) {
int pr=j^(1<<k-1);
for(int l=(i!=1);l<=n;l++)
if(dp[o^1][pr][l]&&abs(id[l]-id[k])>kk) {
if(fl==0) {
dp[o][j][k]=dp[o^1][pr][l];
fl=1;
}
else dp[o][j][k]+=dp[o^1][pr][l];
}
}
if(!fl) dp[o][j][k]=0;
if(i==n)
ans+=dp[o][j][k];
}
}
}
printf("%lld\n",ans);
} void init() {
fastIO::read(n);
fastIO::read(kk);
for(int i=1;i<=n;i++) fastIO::read(id[i]);
} //#define DEBUG
int main() {
#ifdef DEBUG
freopen("1.in","r",stdin);
//freopen(".out","w",stdout);
#endif
init();
pre();
work();
return 0;
}
洛谷 2915 [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 ...
- 洛谷P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows 状压动归
考场上空间开大了一倍就爆0了QAQ- Code: #include<cstdio> #include<algorithm> #include<cmath> usin ...
- 洛谷 P2915 【[USACO08NOV]奶牛混合起来Mixed Up Cows】
类似于n皇后的思想,只要把dfs表示放置情况的数字压缩成一个整数,就能实现记忆化搜索了. 一些有关集合的操作: {i}在集合S内:S&(1<<i)==1: 将{i}加入集合S:S= ...
- [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- 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(状态压缩DP)
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
- 【题解】Luogu2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 Each of Farmer John's N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i & ...
随机推荐
- DNS隧道--dnscat2
安装 服务端 git clone https://github.com/iagox86/dnscat2.git cd dnscat2 cd server sudo gem install bundle ...
- Metasploit 模块和位置
Metasploit Framework由许多的模块组成的. 一.Exploits(漏洞模块) 定义为使用“有效载荷(payloads)”的模块 没有“有效载荷”的攻击是辅助模块 二.Payloads ...
- Vue项目的配置项
目录 Vue项目的配置项 配置项 加载全局css文件 加载全局js文件 store仓库的配置和简单用法 BootStrap环境和jQuery的配置 前端后端交互(CORS问题) axios配置项(前端 ...
- DLL相关下断点
加载DLL 的时候断: sxe ld:[dll] 卸载DLL 的时候断: sxe ud:[dll] 比如: sxe ld:wininet.dll (在wininet.dll 被装载的时候断点) 这里 ...
- JDBC_数据库连接池工具类
//定义一个类JDBCUtils public class JDBCUtils { //1.定义成员方法 private static DataSource ds; //2.提供静态代码块 stati ...
- Spring+SpringMVC+MyBatis+SpringSecurity+EhCache+JCaptcha 完整Web基础框架(前言)
简单介绍一下,本框架的基本功能点: Spring:整个框架的主体部分,这个自不用说. SpringMVC:MVC部分我还是比较喜欢Spring的. MyBatis:选型的时候选择这个ORM主要也是考虑 ...
- Thread-per-Message 这个工作交给你了
Per是“每一”的意思,所以thread per message解释过来就是“每个消息一个线程”,message在这里可以看做是“命令”或“请求”的意思,对每隔命令或请求,分配一个线程,有这个线程执行 ...
- lunix查询jdk安装路径
在linux系统查找jdk的安装路径:whereis javawhich java (java执行路径)echo $JAVA_HOME echo $PATH在windows查找jdk的安装路径:set ...
- SVN Cannot merge into a working copy that has local modifications
我尝试了 主支,分支都提交,但是依然无法合并. 最终,我在服务器上将分支删除,然后主支在拷贝过去. 一,打开服务器资源 二,删除分支 三,拷贝主支到分支 四,刷新分支,就能看到了. 然后在分支项目中, ...
- 导出Excel格式数据
/** * 导出规则统计数据 excel格式 * @param bill * @return */ public String exportExamsignupExamnoExcel ( String ...