One day, zhx takes part in an contest. He found the contest very easy for him.
There are n
As he is too powerful, the administrator is watching him. If he finishes the i
zhx doesn't really want to solve all these boring problems. He only wants to get no less than w
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.
For each test, there are two integers n
Then come n lines which contain three integers t
1 3 1 4 7 3 6 4 1 8 6 8 10 1 5 2 2 7 10 4 1 10 2 3
7 8 zhx is naive!
题意:
- 有n道题i题用时ti秒,得分vi,在li时间点之前不能做出来,而且一道题不能分开几次做(一旦开始做,必须在ti时间内把它做完)
- 问得到w分的最小用时是多少
思路: 把题目按开始做的先后顺序排序,然后o1背包
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1)
#define eps 1e-8
typedef __int64 ll;
#define fre(i,a,b) for(i = a; i <b; i++)
#define free(i,b,a) for(i = b; i >= a;i--)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define ssf(n) scanf("%s", n)
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define bug pf("Hi\n")
using namespace std;
#define INF 0x3f3f3f3f
#define N 100005
int dp[30*N];
struct stud{
int t,l,va;
bool operator < (const stud a) const
{
return l-t<a.l-a.t;
}
}f[40];
int all,sum;
int n,m;
void solve()
{
int i,j;
sort(f,f+n);
int te;
mem(dp,0);
fre(i,0,n)
free(te,all,f[i].l)
if(te>=f[i].t)
dp[te]=max(dp[te],dp[te-f[i].t]+f[i].va);
fre(i,0,all)
if(dp[i]>=m) break;
pf("%d\n",i);
}
int main()
{
int i,j;
while(~sff(n,m))
{
sum=all=0;
int temp=0;
fre(i,0,n)
{
sfff(f[i].t,f[i].va,f[i].l);
all+=f[i].t;
temp=max(temp,f[i].l);
sum+=f[i].va;
}
if(sum<m)
{
pf("zhx is naive!\n");
continue;
}
all=max(all,temp);
solve();
}
return 0;
}
5944



被折叠的 条评论
为什么被折叠?



