题目1030:毕业bg
来源:互联网 发布:销售订单软件 编辑:程序博客网 时间:2024/05/16 18:41
#include<iostream> #include<algorithm> using namespace std; struct bg { int hap; //欢乐度 int last; // 持续时间 int time; //必须离开时间 }; bg b[40]; bool comp(const bg &a, const bg &b) { //先必须离开的在前 return a.time < b.time; } int main() { int n; while (cin >> n && n>0) { int dp[1000] = {0}; for (int i=0; i!=n; ++i) cin >> b[i].hap >> b[i].last >> b[i].time; sort (b, b+n, comp); for (int i=0; i!=n; ++i) //类似01背包选择 for (int j=b[i].time; j>=b[i].last; --j) if (dp[j] < dp[ j-b[i].last ] + b[i].hap) dp[j] = dp[j-b[i].last] + b[i].hap; int ans = 0; for (int i=0; i<=b[n-1].time; ++i) ans = max(ans, dp[i]); cout << ans << endl; }//while return 0; } /************************************************************** Problem: 1030 User: cust123 Language: C++ Result: Accepted Time:0 ms Memory:1520 kb****************************************************************/
#include <iostream>#include <algorithm>#include <queue>#include <vector>#include <cstring>#include <stack>#include <string>#include <string.h>#include <stdio.h>#include <cmath>#include <map>#include <functional>#include <set>#include <limits.h>#include <math.h>#include <ctype.h>using namespace std;//1030struct node{ int a,b,c;}node[31]; bool mark[31];int n,h,l,t,high,sum,mx,ans;void dfs(int high,int sum){ if(high>ans) ans=high; for(int i=1;i<=n;i++) { if(mark[i]==false && sum+node[i].b<=node[i].c) { mark[i]=true; dfs(high+node[i].a,sum+node[i].b); mark[i]=false; } }}int main(){ //freopen("input.txt","r",stdin); while(scanf("%d",&n)!=EOF && n>=0) { memset(mark,0,sizeof(mark)); for(int i=1;i<=n;i++) scanf("%d %d %d",&node[i].a,&node[i].b,&node[i].c); ans=0; dfs(0,0); printf("%d\n",ans); } return 0;}/************************************************************** Problem: 1030 User: cust123 Language: C++ Result: Accepted Time:10 ms Memory:1520 kb****************************************************************/
0 0
- 题目1030:毕业bg
- 题目1030:毕业bg
- 题目1030:毕业bg
- 题目1030:毕业bg
- 九度oj 题目1030:毕业bg
- 九度OJ 题目1030:毕业bg
- 题目1030:毕业bg 进化版01背包
- 九度OJ—题目1030:毕业bg
- HDOJ 题目1881 毕业bg(DFS)
- 毕业bg
- 九度oj 题目1030:毕业bg 【ZJU2008考研机试题5】【经典】
- 九度OJ:题目1030:毕业bg(经典背包问题)
- 题目1030:毕业bg(0-1背包问题的变形)
- hdu 1881 毕业bg
- hdu 1881 毕业bg
- OJ_1030 毕业bg
- HDU 1881 毕业bg
- HDU 1881 毕业bg
- windows电脑连接手机,adb无法识别问题
- CAS-5.1.0-RC3 作为Gradle项目导入Eclipse
- 关于 MySQL 你可能不知道的 SQL 使用技巧
- dlib, OpenFace and face_recognition
- epoll详解
- 题目1030:毕业bg
- CSU-1830 FarAway
- Android 软键盘汇总
- CSS---使用flex布局做响应式页面
- 解决AndroidStudio添加ProjectLibary后在编译时遇到的各种问题之解决方式索引(finished with non-zero exit value and so on...)
- 廖雪峰Python的研读笔记(二) 函数式编程
- C# 操作EXCEL文件
- Java实现全排列、组合算法
- Spring注入Date类型的数据到Bean中