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

Problem Description
As one of the most powerful brushes in the world, zhx usually takes part in all kinds of contests. One day, zhx takes part in an contest. He found the contest very easy for him. There are n problems in the contest. He knows that he can solve the ith problem in ti units of time and he can get vi points. As he is too powerful, the administrator is watching him. If he finishes the ith problem before time li, he will be considered to cheat. zhx doesn't really want to solve all these boring problems. He only wants to get no less than w points. You are supposed to tell him the minimal time he needs to spend while not being considered to cheat, or he is not able to get enough points.  Note that zhx can solve only one problem at the same time. And if he starts, he would keep working on it until it is solved. And then he submits his code in no time.
 
Input
Multiply test cases(less than 50). Seek EOF as the end of the file. For each test, there are two integers n and w separated by a space. (1≤n≤30, 0≤w≤109) Then come n lines which contain three integers ti,vi,li. (1≤ti,li≤105,1≤vi≤109)
 
Output
For each test case, output a single line indicating the answer. If zhx is able to get enough points, output the minimal time it takes. Otherwise, output a single line saying "zhx is naive!" (Do not output quotation marks).
 
Sample Input
1 3
1 4 7
3 6
4 1 8
6 8 10
1 5 2
2 7
10 4 1
10 2 3

 
Sample Output
7 8 zhx is naive!
 
Source

 #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)的更多相关文章

  1. 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 ...

  2. hdu 5188 zhx and contest [ 排序 + 背包 ]

    传送门 zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  3. zhx's contest (矩阵快速幂 + 数学推论)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  4. HDOJ 5188 zhx and contest 贪婪+01背包

    zhx and contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  5. hdu 5187 zhx's contest [ 找规律 + 快速幂 + 快速乘法 || Java ]

    传送门 zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  6. hdu 5187 zhx's contest (快速幂+快速乘)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  7. HDU 4770 Lights Against Dudely 暴力枚举+dfs

    又一发吐血ac,,,再次明白了用函数(代码重用)和思路清晰的重要性. 11779687 2014-10-02 20:57:53 Accepted 4770 0MS 496K 2976 B G++ cz ...

  8. 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 ...

  9. poj 3740 Easy Finding 二进制压缩枚举dfs 与 DLX模板详细解析

    题目链接:http://poj.org/problem?id=3740 题意: 是否从0,1矩阵中选出若干行,使得新的矩阵每一列有且仅有一个1? 原矩阵N*M $ 1<= N <= 16 ...

随机推荐

  1. Sonatype Nexus高级配置

    Sonatype Nexus的安装配置参见:CentOS系统中安装Nexus并导入已有的构件库.Nexus内置了Jetty容器,${NEXUS_HOME}/bin/jsw目录下包含了各个操作系统的启动 ...

  2. 总体最小二乘(TLS)

    对于见得多了的东西,我往往就习以为常了,慢慢的就默认了它的存在,而不去思考内在的一些道理.总体最小二乘是一种推广最小二乘方法,本文的主要内容参考张贤达的<矩阵分析与应用>. 1. 最小二乘 ...

  3. IT男的”幸福”生活"系列暂停更新通知

    首先谢谢博客园,这里给了我很多快乐.更给了大家一个学习的好地方. 在这几天更新过程中,看到了很多哥们的关注,在这里我谢谢你们,是你们给了我动力,是你们又一次给了我不一样的幸福. 在续5中我已回复了,博 ...

  4. org.hibernate.PropertyValueException: not-null property references a null or transient value:

    org.hibernate.PropertyValueException: not-null property references a null or transient value: com.bj ...

  5. JMeter工具的使用-ForEach

    1,Add Thread group this detail information about this panel as below link http://jmeter.apache.org/u ...

  6. __HTML_5读取文件API

    //HTML5 __FileSystemApi <!doctype html> <html> <head> <meta charset="utf-8 ...

  7. java 关键字 transient

    一个对象实现了Serilizable 接口,该对象就可以被序列化. 然而在实际开发工程中,我们会遇到,这个类的有些属性不需要序列化,比如包含用户的敏感信息(如密码),为了安全起见,不希望在网络操作(主 ...

  8. 消灭textarea中的神秘空格

    之前在做页面的时候经常发现写的textarea中会有一些默认的空格出现,鼠标可以在里面任意点击.这个问题折腾了好久,后来发现,原来是<textarea></textarea>标 ...

  9. 【POJ 2485】Highways(Prim最小生成树)

    题目 Prim算法:任选一个点,加入集合,找出和它最近的点,加入集合,然后用加入集合的点去更新其它点的最近距离......这题求最小生成树最大的边,于是每次更新一下最大边. #include < ...

  10. 打印cell的视图层次结构

    #ifdef DEBUG NSLog(@"Cell recursive description:\n\n%@\n\n", [cell performSelector:@select ...