HRBEU Max Use Of CPU(01背包)
来源:互联网 发布:淘宝店铺资质代表什么 编辑:程序博客网 时间:2024/05/16 07:05
Max Use Of CPU
TimeLimit: 1 Second MemoryLimit: 32 Megabyte
Totalsubmit: 11 Accepted: 1
Description
There are n tasks {1,2,3...,n} waiting in line to be operated on the computer. Task i needs Ti CPU time to be finished. Your task is to find a way to maximize the number of tasks can be finished in time T. If there are more than one way containing maximum tasks, then maximize the CPU time used in time T.
Input
The first line contains a integer t (1<=t<=100), the number of test cases. The first line of each case contains integer n and T, representing n tasks and in time T the maximum tasks can be finished and the maximum CPU can be used. The second line of each case contains the time {T1,T2,T3...Tn} each task needs to be finished. All numbers are integer in the input file.
Output
For each test case, output a line with the maximum number of tasks can be finished and the maximum of CPU time can be used in time T. One test case per line and separated by one whitespace.
Sample Input
1
7 47
30 78 33 76 66 8 78
Sample Output
2 41
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 1000005
int f[N],num[N],v,maxans;
void pack01(int cost,int weight){
int i;
for(i=v;i>=cost;i--)
if(f[i-cost]!=-1){
if(f[i-cost]+1>f[i])
f[i]=f[i-cost]+1;
maxans=max(maxans,f[i]);
}
}
int main(){
int i,n,t,cost;
scanf("%d",&t);
while(t--){
maxans=0;
memset(f,-1,sizeof(f));
f[0]=0;
scanf("%d%d",&n,&v);
for(i=1;i<=n;i++){
scanf("%d",&cost);
pack01(cost,cost);
}
for(i=v;i>=0;i--)
if(f[i]==maxans){
printf("%d %d\n",maxans,i);
break;
}
}
return 0;
}
- HRBEU Max Use Of CPU(01背包)
- HEU 5011 Max Use Of CPU
- HRBEU/HEUOJ----1018 Temple of Dune
- 基础算法题解(hrbeu OJ)
- UVA - 10032 Tug of War (二进制标记+01背包)
- poj 3132 Sum of Different Primes(01背包)
- basic use of sidekiq(2)
- 网易2017实习笔试题-CPU双核调度问题(dp 01背包)
- HDOJ 1024 Max Sum Plus Plus 最大K段子序列和(01背包 + 滑动数组 + 优化)
- HDU 1024 Max Sum Plus Plus(求m个不相交连续子序列最大和/01背包)
- hrbeu基础题解(高级数据结构之树状数组)
- HRBEU 占武卖花
- Hrbeu 1255
- Hrbeu 1039
- Hrbeu 1209
- max sum of subtree
- max sum of subtree
- hdu3591 The trouble of Xiaoqian(多重背包 + 完全背包)
- java对象池化
- ubuntu下打开txt文件乱码的解决
- 程序设计入门经典
- POJ_1035题解
- 天勤OJ 题目1135: 素数
- HRBEU Max Use Of CPU(01背包)
- Java对象池技术的原理及其实现
- Linux设备驱动程序:gnu make 扩展语法
- HRBEU 油田合并
- DPL RPL CPL区别与联系
- Super Jumping! Jumping! Jumping!(HDU1087)
- 理解顶点着色器和像素着色器
- 工作成绩和关系的理解
- Andorid 好书籍推荐