南邮 OJ 1996 ELEVATOR
2015-08-08 09:52
288 查看
ELEVATOR
时间限制(普通/Java) : 1000 MS/ 3000 MS 运行内存限制 : 65536 KByte总提交 : 98 测试通过 : 27
比赛描述
In the library of NUPT there is an elevator. The elevator can lift no more than W kg.
And you know in NUPT the library is always crowded.
Here are N people want to get into the elevator. Each people have two facts, the weight and IQ.
I want you to find the minimum of the combined IQ of the people outside the elevator when the combined weight of the people in the elevator is no more than W.
For example: when W,n=200,4
The weight of people are: 65 50 85 55
The IQ of peole are: 46 18 70 21
65+50+85+55=255>W, so the elevator can lift them all.
We chose to lift the 1st,2nd,3rd people, the sum of weight is 200<=W and the sum of IQ of people out of the elevator is 21.
So you have to output 21.
输入
In the first line there is an integer T indicating there T test cases.
In the first of each case, there are two integers W,n.W is the max weight of peole in the elevator, and there are n people.
In the next line there are n integers wi. The ith integer is the ith people’s weight.
In the next line there are n integers vi. The ith integer is the ith people’s IQ.
输出
For each case you only output one integer. The combined IQ of the people outside the elevator.
样例输入
2
0 1
1
1
200 4
65 50 85 55
46 18 70 21
样例输出
1
21
提示
null
题目来源
3B
/* Wrong Answer at Test 1 #include<iostream> int main(){ int t,W,n,i,j,temp,sum; int *w,*v,*f; scanf("%d",&t); while(t--){ scanf("%d%d",&W,&n); w = new int ; v = new int ; f = new int[W+1](); for(i=0;i<n;i++){ scanf("%d",w+i); } sum=0; for(i=0;i<n;i++){ scanf("%d",v+i); sum += v[i]; } for(i=0;i<n;i++){ for(j=W;j>=0;j--){ if(j>=w[i] && f[j]<(temp=f[j-w[i]]+v[i])){ f[j] = temp; } } } for(i=j=0;j<=W;j++){ // printf("j=%d f[j]=%d\n",j,f[j]); if(i<f[j]){ i = f[j]; } } printf("%d\n",sum-i); delete[] w; delete[] v; delete[] f; } } */ /* Internet AC #include<iostream> #include<cstring> #include<cstdlib> #include<cstdio> using namespace std; int main() { int dp[101][1001],m,T,C,w[101],val[101],i,j; scanf("%d",&C); while(C--){ int sum=0; //累加器 scanf("%d%d",&T,&m); for(i=1;i<=m;i++) scanf("%d",&w[i]); //体重 for(i=1;i<=m;i++) { scanf("%d",&val[i]); //IQ值 sum+=val[i]; } memset(dp,0,sizeof(dp)); //置零 for(i=1;i<=m;i++) for(j=0;j<=T;j++) { if(j>=w[i]) dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+val[i]);//放还是不放的选择 else dp[i][j]=dp[i-1][j]; } printf("%d\n",sum-dp[m][T]); } return 0; } //01背包问题的另一种形式 */ #include<iostream> int main(){ int t,W,n,i,j,temp,sum; int *w,*v,*f; scanf("%d",&t); while(t--){ scanf("%d%d",&W,&n); w = new int ; v = new int ; f = new int[W+1]; //在VS上,f = new int[W+1]();会初始化为0,但是OJ上面不会 memset(f,0,(W+1)*sizeof(int)); //WA1 for(i=0;i<n;i++){ scanf("%d",w+i); } sum=0; for(i=0;i<n;i++){ scanf("%d",v+i); sum += v[i]; } for(i=0;i<n;i++){ for(j=W;j>=0;j--){ //从后往前 if(j>=w[i] && f[j]<(temp=f[j-w[i]]+v[i])){ f[j] = temp; } } } for(i=j=0;j<=W;j++){ // printf("j=%d f[j]=%d\n",j,f[j]); if(i<f[j]){ i = f[j]; } } printf("%d\n",sum-f[W]); delete[] w; delete[] v; delete[] f; } }
相关文章推荐
- javascript 调用其他页面的js函数或变量的脚本
- 设计模式---
- 架构师速成8.3-架构师必须要了解的规则(转)
- 关于DDOS攻击
- vc 输出到调试器
- 常用前端开发工具合集
- FZUOJ2196 Escape(bfs)
- 搜索超过大指定大小的文件
- 单例模式
- 南邮 OJ 1999 Snoopy
- android集成apk对一些问题经常遇到系统
- Android之Adapter用法总结
- 南邮 OJ 1988 有序集合
- Android学习心得(11) --- MAC下Android反编译(3)
- Python基础教程笔记——第6章:抽象(函数)
- POJ 3498 && HDU 2334 March of the Penguins(最大流-Dinic)
- 高德地图根绝经纬度画线跑步软件
- JVM垃圾收集(二)垃圾收集算法
- Advanced Graphics and Animations for iOS Apps
- android 屏幕的相对位置