CodeForces864E【DP+路径输出】
2017-09-25 22:21
267 查看
知道题意以后就是一个简单的:
0/1背包+路径输出???
MMP???写C的时间不如写E
0/1背包+路径输出???
MMP???写C的时间不如写E
//#pragma comment(linker, "/STACK:102400000,102400000") #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef long long LL; struct asd{ int t, d, p, id; }node[110]; bool cmp(asd x, asd y){ return x.d < y.d; } int n; int prex[110][2100], prey[110][2100]; pair<int,int>dp[2100]; vector<int>ans; int main(){ scanf("%d", &n); for(int i=1;i<=n;i++){ scanf("%d%d%d",&node[i].t, &node[i].d, &node[i].p); node[i].id = i; } sort(node+1, node+n+1, cmp); for(int i=0;i<=2000;i++){ dp[i].first = 0; dp[i].second = -1; } memset(prex, -1, sizeof(prex)); for(int i=1;i<=n;i++){ for(int j=node[i].d-node[i].t-1;j >= 0;j--){ if(dp[j+node[i].t].first < dp[j].first + node[i].p) { prex[node[i].id][j+node[i].t] = dp[j].second; prey[node[i].id][j+node[i].t] = j; dp[j+node[i].t].first = dp[j].first + node[i].p; dp[j+node[i].t].second = node[i].id; } } } int Max = 0, pos; for(int i=0;i<=2000;i++) if(dp[i].first > Max){ Max = dp[i].first; pos = i; } printf("%d\n", Max); int x, y, xx, yy; x = dp[pos].second; y = pos; while(x != -1){ ans.push_back(x); xx = x;yy = y; x = prex[xx][yy]; y = prey[xx][yy]; } printf("%d\n", (int)ans.size()); for(int i=(int)ans.size()-1;i>=0;i--) printf("%d ", ans[i]); return 0; }
相关文章推荐
- Codeforces 119C Education Reform【dp+路径输出】
- 选课 树形dp+路径输出
- dfs路径输出
- URAL1004 Sightseeing Trip(floyd+路径输出)
- main方法中输出当前环境的路径
- MySQL数据库中的日志文件---(4)配置日志文件输出路径
- 两个输出文件名解析为同一个输出路径:“obj\x86\Debug\xxxxxxxxxxxxx.resources”
- 输入和输出--javase中的路径
- log4j 设置日志输出文件的路径
- Eclipse设置编译文件.class输出路径
- POJ 3984 迷宫问题 手写队列+BFS路径输出
- 修改VS2010中工程文件的输出路径Output
- C#将制定文件夹下的PDF文件合并成一个并输出至指定路径
- 改变工程的输出文件路径和利用Copy命令Copy移动某个文件
- 设计一个算法,输出从u到v的所有最短路径(采用邻接表存储)
- ASP.NET MVC 获取项目路径与输出信息到控制台
- Flex变更输出文件夹路径指向当前项目当中的bin-debug中
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
- 输出指定路径下指定后缀的文件名
- 【最大流+输出路径】POJ-3436 ACM Computer Factory