Codeforces Round #436 (Div. 2) E
来源:互联网 发布:多益网络客服电话 编辑:程序博客网 时间:2024/06/10 14:16
传送门
题意:
n个物品,每个物品有个需要拯救花的时间,截止时间,物品价值。
让你能救回的最大价值,打印选择方式。
做法:
这这这,这不就是,是个01背包吗。
//china no.1#pragma comment(linker, "/STACK:1024000000,1024000000")#include <vector>#include <iostream>#include <string>#include <map>#include <stack>#include <cstring>#include <queue>#include <list>#include <stdio.h>#include <set>#include <algorithm>#include <cstdlib>#include <cmath>#include <iomanip>#include <cctype>#include <sstream>#include <functional>#include <stdlib.h>#include <time.h>#include <bitset>using namespace std;#define pi acos(-1)#define s_1(x) scanf("%d",&x)#define s_2(x,y) scanf("%d%d",&x,&y)#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)#define S_1(x) scan_d(x)#define S_2(x,y) scan_d(x),scan_d(y)#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)#define PI acos(-1)#define endl '\n'#define srand() srand(time(0));#define me(x,y) memset(x,y,sizeof(x));#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)#define close() ios::sync_with_stdio(0); cin.tie(0);#define FOR(x,n,i) for(int i=x;i<=n;i++)#define FOr(x,n,i) for(int i=x;i<n;i++)#define fOR(n,x,i) for(int i=n;i>=x;i--)#define fOr(n,x,i) for(int i=n;i>x;i--)#define W while#define sgn(x) ((x) < 0 ? -1 : (x) > 0)#define bug printf("***********\n");#define db double#define ll long long#define mp make_pair#define pb push_backtypedef long long LL;const int INF=0x3f3f3f3f;const LL LINF=0x3f3f3f3f3f3f3f3fLL;const int dx[]={-1,0,1,0,1,-1,-1,1};const int dy[]={0,1,0,-1,-1,1,-1,1};const int maxn=1e5+10;const int maxx=200005;const double EPS=1e-8;const double eps=1e-8;const int mod=1e9+7;template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}template <class T>inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}if(IsN) num=-num;return true;}void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}void print(LL a){ Out(a),puts("");}//freopen( "in.txt" , "r" , stdin );//freopen( "data.txt" , "w" , stdout );//cerr << "run time is " << clock() << endl;int n;struct node{ int t,d,p,id;}Q[110];bool cmp(node a,node b){ return a.d<b.d;}vector<int>q[2010],ans2;int dp[2010];int main(){ W(S_1(n)) { me(dp,0); me(Q,0); ans2.clear(); FOR(1,n,i) { q[i].clear(); S_3(Q[i].t,Q[i].d,Q[i].p); Q[i].id=i; } sort(Q+1,Q+n+1,cmp); FOR(1,n,i) { for(int j=Q[i].d-1;j>=Q[i].t;j--) { if(dp[j]<dp[j-Q[i].t]+Q[i].p) { dp[j]=dp[j-Q[i].t]+Q[i].p; q[j]=q[j-Q[i].t]; q[j].pb(Q[i].id); } } } int ans=0; FOR(1,2000,i) { if(dp[i]>ans) { ans=dp[i]; ans2=q[i]; } } printf("%d\n%d\n",ans,ans2.size()); FOr(0,ans2.size(),i) { if(i==0) printf("%d",ans2[i]); else printf(" %d",ans2[i]); } puts(""); }}
阅读全文
0 0
- Codeforces Round #436 (Div. 2) E. Fire
- Codeforces Round #436 (Div. 2)E.Fire
- Codeforces Round #436 (Div. 2) E
- Codeforces Round #436 (Div. 2)E. Fire
- Codeforces Round #436 (Div. 2) E. Fire
- Codeforces Round #436 (Div. 2) E fire DP
- Codeforces Round #436 (Div. 2)E,F详解
- Codeforces Round #436 (Div. 2) 864E. Fire
- Codeforces 405E Codeforces Round #238 (Div. 2)E
- Codeforces Round #103 (Div. 2) E题
- Codeforces Round #147 (Div. 2) E
- Codeforces Round #184 (Div. 2) D、E
- Codeforces Round #197 (Div. 2) (C~E)
- Codeforces Round #102 (Div. 2) //缺E
- Codeforces Round #104 (Div. 2) //缺E
- Codeforces Round #105 (Div. 2) //缺E
- Codeforces Round #103 (Div. 2) //缺E
- Codeforces Round #106 (Div. 2) //缺E
- day1对象
- Surround the Trees HDU
- Gitolite + repo 搭建安卓源码开发环境
- 翻转单词顺序列
- 使用python在Window10下配置tensorflow
- Codeforces Round #436 (Div. 2) E
- 左旋转字符串
- SpringMVC简例HelloWorld~
- Linux C编程 GCC的使用
- Visual Studio Enterprise 2017 ReferenceManagerPackage的解决方案
- springMvc执行流程简介
- 和为S的两个数字
- 和为S的连续正数序列
- [cnblogs镜像] Unity官方宣传片Adam 播放地址