zhx and contest (枚举 + dfs)
zhx and contest
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 324 Accepted Submission(s): 118
1 4 7
3 6
4 1 8
6 8 10
1 5 2
2 7
10 4 1
10 2 3
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <ctime>
#include <numeric>
#include <vector>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <complex>
#include <deque>
#include <functional>
#include <list>
#include <map>
#include <string>
#include <sstream>
#include <set>
#include <stack>
#include <queue>
using namespace std;
template<class T> inline T sqr(T x) { return x * x; }
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<PII, int> PIII;
typedef pair<LL, LL> PLL;
typedef pair<LL, int> PLI;
typedef pair<LD, LD> PDD;
#define MP make_pair
#define PB push_back
#define sz(x) ((int)(x).size())
#define clr(ar,val) memset(ar, val, sizeof(ar))
#define istr stringstream
#define FOR(i,n) for(int i=0;i<(n);++i)
#define forIt(mp,it) for(__typeof(mp.begin()) it = mp.begin();it!=mp.end();it++)
const double EPS = 1e-;
const int INF = 0x3fffffff;
const LL LINF = INF * 1ll * INF;
const double PI = acos(-1.0); #define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define lowbit(u) (u&(-u)) using namespace std; #define MAXN 35 struct Question{
int t,v,l;
bool operator<(const Question& q) const{
return l - t < q.l - q.t ;
}
} q[MAXN]; LL remain[MAXN];
int n,w; bool dfs(int cur,int t,LL val){
if(val>=w) return true;
if(cur<) return false;
if(val+remain[cur]<w) return false;
if(t>=q[cur].l&&t>=q[cur].t)
if(dfs(cur-,t-q[cur].t,val+q[cur].v)) return true;
if(dfs(cur-,t,val)) return true;
return false;
} int main(void){
#ifndef ONLINE_JUDGE
freopen("a.txt","r",stdin);
#endif
while(scanf("%d %d",&n,&w)!=EOF){
LL sum = ;
FOR(i,n) scanf("%d %d %d",&q[i].t,&q[i].v,&q[i].l);
sort(q,q+n);
for(int i = ;i<n;i++){
if(i==) remain[i] = q[i].v;
else remain[i] = remain[i-]+q[i].v;
}
if(remain[n-]<w){
puts("zhx is naive!");
continue;
}
int ans = INF;
int low = ,high = *n;
while(low<=high){
int mid = (low+high)>>;
if(dfs(n-,mid,)){
high = mid-;
ans = mid;
}else low = mid+;
}
printf("%d\n",ans);
}
return ;
}
一个简单的想法是状态压缩dp。
但是30的数据范围存不下来。
首先发现如果选定了做哪些题的话,按题的l值递增的顺序做一定不会更劣。
然后我们把所有题按 l - t 排序,分成大小相同(或者相差1)的两部分。
对于前一部分,枚举出所有可能的取法的得分和结束时间。然后把它们按照得分排序。可以算出得分不少于某个值的时候完成时间最早是多少。
然后对于后一部分也是相同的枚举,然后在得分符合条件的里面找完成时间最早的,用和上面相同的办法就可以处理出答案。
zhx and contest (枚举 + dfs)的更多相关文章
- POJ 2965 The Pilots Brothers' refrigerator【枚举+dfs】
题目:http://poj.org/problem?id=2965 来源:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26732#pro ...
- hdu 5188 zhx and contest [ 排序 + 背包 ]
传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- zhx's contest (矩阵快速幂 + 数学推论)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- HDOJ 5188 zhx and contest 贪婪+01背包
zhx and contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]
传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 5187 zhx's contest (快速幂+快速乘)
zhx's contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) To ...
- HDU 4770 Lights Against Dudely 暴力枚举+dfs
又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...
- URAL 1208 Legendary Teams Contest(DFS)
Legendary Teams Contest Time limit: 1.0 secondMemory limit: 64 MB Nothing makes as old as years. A l ...
- poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析
题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...
随机推荐
- 记一次w3wp占用CPU过高的解决过程(Dictionary和线程安全)
项目上线以来一直存在一个比较揪心的问题,和一个没有信心处理的BUG,那就是在应用程序启动时有可能会导致cpu跑满99%或持续在一个值如50%左右,这样一来对服务器的压力是非常大的,经常出现服务器无法远 ...
- bt协议详解 DHT篇(上)
bt协议详解 DHT篇(上) 最近开发了一个免费教程的网站,突然产生了仔细了解bt协议的想法,这篇文章是bt协议详解系列的第三篇,后续还会写一些关于搜索和索引的东西,都是在开发这个网站的过程中学习到的 ...
- 我从腾讯那“偷了”3000万QQ用户数据,出了份很有趣的独家报告!
声明: 1.目前程序已停止运行!QQ空间也已升级访问安全机制. 2.本“分析”数据源自部分用户的公开信息,并未触及隐私内容,广大网友无需担心. 3.QQ空间会不定期发布大数据分析报告,感兴趣的朋友关注 ...
- bcd 8421码
bcd码表: 比如一个字符串 String s = "0200" 按对照表转换成二进制 02 : 0000 0010 00 : 0000 0000 s转换为字节的时候 02和00分 ...
- Android新组件RecyclerView介绍,其效率更好
今天我们首先来说为什么要介绍这个新组件RecyclerView,因为前几天我发布了一个常用面试题ListView的复用及如何优化的文章,介绍给一些开发者,但是我看到有关的反馈说:现在都不再用listv ...
- WCF 入门 (18)
前言 感冒了呀...but 不忌油炸,不忌辛辣,o(∩_∩)o . 第18集 WCF服务应该抛出fault 异常 Throwing fault exceptions from a WCF servic ...
- WCF 入门(15)
前言 度过了一个阳光明媚的周末. 一个阴霾的周日夜晚. 第15集 WCF里面的异常处理(1) Exception handling in WCF 大致看了一下,这个WCF视频里面总共有6集,这个是第 ...
- Javascript基础系列之(三)数据类型 (数值 Number)
javascript中想限定一个数的数值,无需限定它是整数还是浮点数型 var num1 = 80 ; var num2 = 55.51; var num3 = -34; var num4 = 9e5 ...
- Grovvy之解析XML文件
假设现有customer.xml 文件内容如下: <?xml version="1.0" ?> <customers> <corporate> ...
- Customizing Navigation Bar and Status Bar
Like many of you, I have been very busy upgrading my apps to make them fit for iOS 7. The latest ver ...