第八届省赛K题(贪心+01背包)
来源:互联网 发布:网络好但是迅雷下载慢 编辑:程序博客网 时间:2024/06/03 18:02
CF
Problem Description
LYD loves codeforces since there are many Russian contests. In an contest lasting for T minutes there are n problems, and for the ith problem you can get ai−di∗tipoints, where ai indicates the initial points, di indicates the points decreased per minute (count from the beginning of the contest), and ti stands for the passed minutes when you solved the problem (count from the begining of the contest).
Now you know LYD can solve the ith problem in ci minutes. He can't perform as a multi-core processor, so he can think of only one problem at a moment. Can you help him get as many points as he can?
Input
The first line contains two integers n,T(0≤n≤2000,0≤T≤5000).
The second line contains n integers a1,a2,..,an(0<ai≤6000).
The third line contains n integers d1,d2,..,dn(0<di≤50).
The forth line contains n integers c1,c2,..,cn(0<ci≤400).
Output
Output an integer in a single line, indicating the maximum points LYD can get.
Example Input
3 10100 200 2505 6 72 4 10
Example Output
#include<stdio.h>int main(){int n, v;int i, j; int val[1002] = { 0 }, w[1002] = { 0 }; int dp[1002]= { 0 };int t,k;while(scanf("%d",&t)!=EOF) { while (t--) {scanf("%d%d", &n, &v);for (i = 1; i <= n; i++)scanf("%d", &val[i]);for (i = 1; i <= n; i++)scanf("%d", &w[i]);for (i = 1; i <= n; i++){for (j = v; j >= w[i]; j--){if (dp[j - w[i]] + val[i] > dp[j]){dp[j] = dp[j - w[i]] + val[i];}}for(k=0;k<=v;++k) { if(k==v) printf("%d\n",dp[k]); else printf("%d ",dp[k]); }}printf("%d\n", dp[v]); } }return 0;}该题的代码
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int max(int a,int b){ return (a>b)?a:b;}typedef struct{ int a,b,c; float f;}num;bool cmp(num n,num m){ return n.f>m.f;}num node[2005];int main(){ int dp[5005]={0}; int n,t; cin>>n;cin>>t; int i,j; for(i=0;i<n;++i) { cin>>node[i].a; } for(i=0;i<n;++i) { cin>>node[i].b; } for(i=0;i<n;++i) { cin>>node[i].c; } for(i=0;i<n;++i) { node[i].f=(float)node[i].b/(float)node[i].c;//求单位时间消耗分数的快慢 } sort(node,node+n,cmp);//以单位时间内消耗分数最快的从大到小排序 int k=0; int x=0; for(i=0;i<n;++i) { for(j=t;j>=node[i].c;--j) { dp[j]=max(dp[j],dp[j-node[i].c]+node[i].a-j*node[i].b); k=max(k,dp[j]);//max一定存在能做的题的时间加起来的对应的数组元素上 } } cout<<k<<endl; return 0;}
- 第八届省赛K题(贪心+01背包)
- CF----思维排序+01背包 山东省第八届省赛K题
- 2017第八届浪潮杯山东省赛 K题 codeforces 贪心+背包
- 山东省第八届ACM省赛K题 CF(01背包,技巧得排序)
- qduoj codeforces 山东省第八届acm省赛K题 CF (排序+01背包)
- 山东省第八届ACM省赛 K 题 CF (排序01背包)
- 山东省第八届acm省赛K题 贪心+dp
- hdu3466(01背包,贪心)
- hdu 2546 饭卡(01背包+贪心)
- hdu 2546 饭卡(贪心+01背包)
- hdu2159(贪心+01背包)
- UVALive3637(01背包+贪心)
- 饭卡 01背包 + 贪心
- hdu2639-01背包(第k大背包问题)
- hdu2639(01背包变形-第k大背包)
- acm省赛K题--01背包
- hdu2639(01背包k优解)
- 01背包(第k优值)
- C++_009_数据结构_线性表_间接寻址方式储存
- 二、vault
- HDU 1541 Stars
- 蓝桥杯 历届试题 网络寻路(暴力 dfs)
- 第七届蓝桥杯决赛真题
- 第八届省赛K题(贪心+01背包)
- Gson 操作
- 集合框架(二)
- C 文件读写
- flashback
- PAT-A-1053. Path of Equal Weight (30)
- AOJ.805 2016算法课期末考试1
- Sarsa(λ) and Q(λ) in Tabular Case
- webpack---用到过的加载器loader