题目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
原创粉丝点击