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. Sqlite3 设置插入触发器

    需求: 数据库中表t_VerifyCsmDetail需要最多保存10W条记录,超出时删除最旧的那一条. 思路:设置插入触发器.插入前先判断表中记录总数,如果大于99999条,则删除最旧的一条记录. 代 ...

  2. Redis入门学习(一)——安装配置

    最近马上要找实习了,听学长说他们公司里用了redis来解决缓存问题,在大三结束前来学习一下. 问:Redis是什么? 答:(官方)REmote DIctionary Server(Redis)是一个K ...

  3. ModelProxy 前端接口配置建模框架

    ModelProxy    轻量级的接口配置建模框架(1) 先看一下这个博客说明为什么需要用ModelProxy的前端轻量级的框架吧:  http://developer.51cto.com/art/ ...

  4. 编写高质量代码改善C#程序的157个建议[匿名类型、Lambda、延迟求值和主动求值]

    前言 从.NET3.0开始,C#开始一直支持一个新特性:匿名类型.匿名类型由var.赋值运算符和一个非空初始值(或以new开头的初始化项)组成.匿名类型有如下基本特性: 1.既支持简单类型也支持复杂类 ...

  5. WCF入门(11)

    前言 终于出太阳了. 可惜风太大,凉在阳台上的衣服全被吹到了地上,外加几双袜子被吹掉了,gone. 第11集 Difference between DataContract and MessageCo ...

  6. GCD 深入理解:第二部分

    在本系列的第一部分中,你已经学到超过你想像的关于并发.线程以及GCD 如何工作的知识.通过在初始化时利用 dispatch_once,你创建了一个线程安全的 PhotoManager 单例,而且你通过 ...

  7. MySQL 5.6 my.cnf 参数说明

    # 以下选项会被MySQL客户端应用读取. # 注意只有MySQL附带的客户端应用程序保证可以读取这段内容. # 如果你想你自己的MySQL应用程序获取这些值. # 需要在MySQL客户端库初始化的时 ...

  8. gitlab 配置邮箱

    摘自:http://www.tuicool.com/articles/ruyERz 这里我用的是263企业邮箱 这里我们用smtp发送邮件,要是系统自带有sendmail,我们就给他卸掉,yum re ...

  9. hdu5536 字典树xor

    一想到xor还要求最大类似的题,字典树效率高. 此代码c++ TLE. #include<stdio.h> #include<string.h> ; struct node { ...

  10. 在Eclipse 中下载 开源中国码云上的项目

    功能:使用开源中国代码托管(码云)来托管代码,本地的使用Eclipse,该如何配置? 步骤: 1/  在码云 上建一个工程,(为了访问托管工程的权限) 2/  在eclipse中打开名字叫做“Git ...