NYOJ 747 螞蟻的難題(三)

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   strong   

螞蟻的難題(三)時間限制:2000 ms  |  記憶體限制:65535 KB難度:4 
描述

螞蟻終於把儘可能多的食材都搬回家了,現在開始了大廚計劃。

已知一共有 件食材,每件食材有一個美味度 Ai 和新鮮度 Bi , 如果螞蟻在第t時刻將第i樣食材烹飪成功,則得到Ai-t*Bi 的美味指數,當然,用第i件食材做飯要花去 Ci 的時間。

眾所周知,螞蟻的廚藝不怎麼樣,所以他需要你設計做飯方案使得在時間  內完成的美味指數最大。
 
輸入
有多組測試資料。
第一行是兩個正整數,表示螞蟻的做飯時間T和食材個數n。(n<=50, 1<=T<=100000)。
接下來n行,每行有三個數,Ai,Bi,Ci。分別代表美味度、新鮮度和用該食材做飯花費的時間。(0<Ai,Bi,Ci<=100000).
輸出
輸出一個數字,表示最大美味指數
範例輸入
6 1200 5 1
範例輸出
195
來源
螞蟻系列
上傳者
ACM_李如兵


解題:這道題目跟那個排隊檢查身體一樣。。。。^_^。。。。。
假設優先選擇第一件食材,那麼有
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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.