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 <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large letters on a gold plate hung around her ample bovine neck.
Gangsta cows are rebellious and line up to be milked in an order called 'Mixed Up'. A cow order is 'Mixed Up' if the sequence of serial numbers formed by their milking line is such that the serial numbers of every pair of consecutive cows in line differs by more than K (1 <= K <= 3400). For example, if N = 6 and K = 1 then 1, 3, 5, 2, 6, 4 is a 'Mixed Up' lineup but 1, 3, 6, 5, 2, 4 is not (since the consecutive numbers 5 and 6 differ by 1).
How many different ways can N cows be Mixed Up?
For your first 10 submissions, you will be provided with the results of running your program on a part of the actual test data.
POINTS: 200
约翰家有N头奶牛,第i头奶牛的编号是Si,每头奶牛的编号都是唯一的。这些奶牛最近 在闹脾气,为表达不满的情绪,她们在挤奶的时候一定要排成混乱的队伍。在一只混乱的队 伍中,相邻奶牛的编号之差均超过K。比如当K = 1时,1, 3, 5, 2, 6, 4就是一支混乱的队伍, 而1, 3, 6, 5, 2, 4不是,因为6和5只差1。请数一数,有多少种队形是混乱的呢?
输入输出格式
输入格式:
Line 1: Two space-separated integers: N and K
- Lines 2..N+1: Line i+1 contains a single integer that is the serial number of cow i: S_i
输出格式:
- Line 1: A single integer that is the number of ways that N cows can be 'Mixed Up'. The answer is guaranteed to fit in a 64 bit integer.
输入输出样例
说明
The 2 possible Mixed Up arrangements are:
3 1 4 2
2 4 1 3
简单的装压dp
保证后一个状态比前一个小
题目没有翻译long long
#include<cstdio>
#include<algorithm>
const int maxn = ;
#define LL long long
inline int read() {
int x=,f=;
char c=getchar() ;
while(c<''||c>''){ if(c=='-')f=-;c=getchar();};
while(c<=''&&c>='')x=x*+c-'',c=getchar();
return x*f;
}
int n,op,s[maxn];
LL dp[maxn][<<maxn];
int main() {
n=read(),op=read();
for(int i=;i<=n;++i) {
s[i]=read();
}
for(int i=;i<=n;++i) {
dp[i][<<i-]=;
}
for(int j=;j<=(<<n)+;++j)
for(int i=;i<=n;++i) {
if((<<i-)&j) {
for(int k=;k<=n;k++) {
if(!(j&(<<k-))&&abs(s[i]-s[k])>op) {
dp[k][j|(<<k-)]+=dp[i][j];
}
}
}
}
LL ans=;
for(int i=;i<=n;++i) {
ans+=dp[i][(<<n)-];
}
printf("%lld\n",ans);
return ;
}
luogu 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 ...
- P2915 [USACO08NOV]奶牛混合起来Mixed Up Cows
题目描述 约翰家有N头奶牛,第i头奶牛的编号是Si,每头奶牛的编号都是唯一的.这些奶牛最近 在闹脾气,为表达不满的情绪,她们在挤奶的时候一定要排成混乱的队伍.在一只混乱的队 伍中,相邻奶牛的编号之差均 ...
- 洛谷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= ...
- Luogu P2915 [USACO08NOV]奶牛混合起来
题外话: 是非常颓废的博主 写题解也不在于能不能通过啦,主要是缓解颓废 首先看到这个题,肯定是可以暴力搜索的: 不得不说这道题还是很善良的,一波大暴力dfs,居然有70pts: #include< ...
- [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 & ...
随机推荐
- sql优化系列2
sql中索引是否会用到,进而影响查询效率. 带通配符(%)的like语句 1.不能用null作索引,任何包含null值的列都将不会被包含在索引中.即使索引有多列这样的情况下,只要这些列中有一列含有nu ...
- [原]sencha touch之carousel
carousel组件是个非常不错的东东,自带可滑动的效果,效果如下图 上面部分可以左右滑动,下面部分可以上下滑动,效果还是不错的,app程序中很有用的布局 代码如下: Ext.application( ...
- 使用vue+webpack的多页面架构(转+自己的情况)
按以下步骤可正常配置多页面架构 记得安装 node-glob 安装命令:npm install node-glob --save-dev 文件附加 webpack.base.conf.js --参 ...
- Python 内置函数isinstance
isinstance 用来判断对象的类型 isinstance(对象,类型/类型集合) 如果属于 返回True 不属于返回 False >>> a = 1 >>> ...
- 线段树&树状数组模板
树状数组: #include <bits/stdc++.h> using namespace std; ; struct binit { int a[MAXN], n; void modi ...
- 菜鸟之路——机器学习之Kmeans聚类个人理解及Python实现
一些概念 相关系数:衡量两组数据相关性 决定系数:(R2值)大概意思就是这个回归方程能解释百分之多少的真实值. Kmeans聚类大致就是选择K个中心点.不断遍历更新中心点的位置.离哪个中心点近就属于哪 ...
- CentOS7重新生成 /boot/grub2/grub.cfg
CentOS7重新生成 /boot/grub2/grub.cfg CentOS7 is using grub2 and the generated /boot/grub2/grub.cfg rathe ...
- BZOJ3999 [TJOI2015]旅游 【树剖 + 线段树】
题目 为了提高智商,ZJY准备去往一个新世界去旅游.这个世界的城市布局像一棵树.每两座城市之间只有一条路径可 以互达.每座城市都有一种宝石,有一定的价格.ZJY为了赚取最高利益,她会选择从A城市买入再 ...
- 关于5Gwifi
但目前全球最快的WiFi传输速度仅为300Mbps(少数可以达到600Mbps),相当于每秒只能传输约36MB的内容.在人们只利用它来看网站.处理邮件的年代,这没什么问题.但到了今天,面对越来越复杂的 ...
- 【05】Vue 之 实例详解与生命周期
Vue的实例是Vue框架的入口,其实也就是前端的ViewModel,它包含了页面中的业务逻辑处理.数据模型等,当然它也有自己的一系列的生命周期的事件钩子,辅助我们进行对整个Vue实例生成.编译.挂着. ...