Nyoj 747 ant financial problems (III)

Source: Internet
Author: User
Ant financial problems (III)Time Limit: 2000 MS | memory limit: 65535 kb difficulty: 4
Description

Ant finally moved as many ingredients as possible back home, and now started the chef program.

Known to allNFood Ingredients, each of which has a delicious tasteAIAnd freshnessBiIf ant financialTAlways changeIThe sample food is successfully cooked.Ai-T * biOf course, it takes time to cook with the I-th foodCi.

As we all know, ant's cooking is not very good, so he needs you to design a cooking solution so that TComplete the most delicious index.
 
Input
There are multiple groups of test data.
The first line is two positive integers, indicating the ant's cooking time t and the number of ingredients n. (N <= 50, 1 <= T <= 100000 ).
Next n rows, each row has three numbers: AI, Bi, and CI. It represents the taste, freshness, and time spent cooking with the food. (0 <AI, Bi, CI <= 100000 ).
Output
Output A number indicating the maximum delicious Index
Sample Input
6 1200 5 1
Sample output
195
Source
Ant Series
Uploaded
ACM _ Li rubing


Problem solving: This question is the same as the physical examination in the queue .... ^_^ .....
Assume that the first food item is preferred.
A1-c1b1 + A2-(C1 + C2) B2> a2-c2b2 + A1-(C1 + C2) B 1
=> c1b2 < c2b1

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cstdlib> 5 #include <vector> 6 #include <climits> 7 #include <algorithm> 8 #include <cmath> 9 #define LL long long10 using namespace std;11 struct node {12     int a,b,c;13 } p[52];14 int dp[100010];15 bool cmp(const node &x,const node &y) {16     return y.c*x.b > x.c*y.b;17 }18 int main() {19     int t,n,i,j,ans;20     while(~scanf("%d %d",&t,&n)) {21         for(i = 0; i < n; i++)22             scanf("%d %d %d",&p[i].a,&p[i].b,&p[i].c);23         sort(p,p+n,cmp);24         memset(dp,0,sizeof(dp));25         for(ans = i = 0; i < n; i++) {26             for(j = min(t,p[i].a/p[i].b); j >= p[i].c; j--) {27                 dp[j] = max(dp[j],dp[j-p[i].c]+p[i].a-j*p[i].b);28                 if(dp[j] > ans) ans = dp[j];29             }30         }31         printf("%d\n",ans);32     }33     return 0;34 }
View code

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.