01背包_The Highest Mark

source

Description

The SDOI in 20452045 is far from what it was been 3030 years ago. Each competition has tt minutes and nn problems.

The ithith problem with the original mark of Ai(Ai≤106)Ai(Ai≤106),and it decreases BiBi by each minute. It is guaranteed that it does not go to minus when the competition ends. For example someone solves the ithith problem after xx minutes of the competition beginning. He/She will get Ai?Bi?xAi?Bi?x marks.

If someone solves a problem on xx minute. He/She will begin to solve the next problem on x+1x+1 minute.

dxy who attend this competition with excellent strength, can measure the time of solving each problem exactly.He will spend Ci(Ci≤t)Ci(Ci≤t) minutes to solve the ith problem. It is because he is so godlike that he can solve every problem of this competition. But to the limitation of time, it's probable he cannot solve every problem in this competition. He wanted to arrange the order of solving problems to get the highest mark in this competition.
Input
There is an positive integer T(T≤10)T(T≤10) in the first line for the number of testcases.(the number of testcases with n>200n>200 is no more than 55)

For each testcase, there are two integers in the first line n(1≤n≤1000)n(1≤n≤1000) and t(1≤t≤3000)t(1≤t≤3000) for the number of problems and the time limitation of this competition.

There are nn lines followed and three positive integers each line Ai,Bi,CiAi,Bi,Ci. For the original mark,the mark decreasing per minute and the time dxy of solving this problem will spend.

Hint:
First to solve problem 22 and then solve problem 11 he will get 8888 marks. Higher than any other order.
Output
For each testcase output a line for an integer, for the highest mark dxy will get in this competition.

Sample Input

1
4 10
110 5 9
30 2 1
80 4 8
50 3 2

Sample Output

88

結(jié)題報(bào)告

#include<cstdio>
#include<algorithm>
#include<string.h>
using namespace std;
struct Node{
    int A;
    int B;
    int C;
    bool operator <(const Node &t)
    {
        return (long long)B*(t.C)>(long long)(t.B)*C;

    }
} arr[3500];
int dp[3500];
int main() {

    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n,t;
        memset(dp,0,sizeof(dp));
        scanf("%d%d",&n,&t);
        for(int i=1;i<=n;i++)
        {
            scanf("%d%d%d",&arr[i].A,&arr[i].B,&arr[i].C );

        }
        sort(arr+1,arr+n+1);
        for(int i=1;i<=n;i++){
            for(int j=t;j>=arr[i].C;j--)
            {
                dp[j]=max(dp[j],dp[j-arr[i].C]+arr[i].A-arr[i].B*j);
            }
        }
         int ans = 0;
        for(int i = 0; i <= t; i++) {
            ans = max(ans, dp[i]);
        }
        printf("%d\n", ans);
    }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 11,259評(píng)論 0 23
  • 1. 2010年,是我人生中最艱難的一年。 那一年,我因中斷工作脫產(chǎn)學(xué)習(xí),成了無工作、無收入、無存款的三無人員。日...
    黃愛春秋閱讀 788評(píng)論 1 9
  • 夜,還是那般安靜 可惜從來沒有你 天,依舊按時(shí)亮起 只是回不到過去 不知道怎么說愛你
    SogoodIT閱讀 232評(píng)論 0 0

友情鏈接更多精彩內(nèi)容