标签:
Time Limit: 1000MS | Memory Limit: 30000K | |
Total Submissions: 4705 | Accepted: 1489 |
Description
Input
Output
Sample Input
8 4 3 2 2 3 2 3 3 3 5 1 1 7
Sample Output
17
Hint
1 #include<stdio.h> 2 #include<algorithm> 3 #include<iostream> 4 #include<string.h> 5 #include<stdlib.h> 6 #include<queue> 7 #include<stack> 8 using namespace std; 9 typedef long long LL; 10 typedef struct node 11 { 12 int cost; 13 int id; 14 bool operator<(const node &cx)const 15 { 16 if(cx.cost == cost)return cx.id < id; 17 else return cx.cost>cost; 18 } 19 } ak; 20 typedef struct pp 21 { 22 int l,p,s; 23 } ss; 24 bool cmp(pp p,pp q) 25 { 26 return p.s<q.s; 27 } 28 priority_queue<ak>que; 29 ss ans[105]; 30 int dp[105][16005]; 31 ak quq[2*16005]; 32 int main(void) 33 { 34 int n,m; 35 while(scanf("%d %d",&n,&m)!=EOF) 36 { 37 int j; 38 int i; 39 int maxx = 0; 40 for(i = 1; i <= m; i++) 41 scanf("%d %d %d",&ans[i].l,&ans[i].p,&ans[i].s); 42 sort(ans+1,ans+1+m,cmp); 43 memset(dp,0,sizeof(dp)); 44 for(i = 1; i <= m; i++) 45 { 46 int head = 16001; 47 int rail = 16000; 48 for(j = 0; j < ans[i].s; j++) 49 { 50 dp[i][j] = dp[i-1][j]; 51 ak acc; 52 acc.cost = dp[i-1][j]-j*ans[i].p; 53 acc.id = j; 54 if(head>rail) 55 quq[--head] = acc; 56 else 57 { 58 ak cpp = quq[rail]; 59 while(cpp.cost < acc.cost) 60 { 61 rail--; 62 if(rail<head) 63 { 64 break; 65 } 66 cpp = quq[rail]; 67 } 68 quq[++rail] = acc; 69 } 70 maxx = max(maxx,dp[i][j]); 71 } 72 for(j = ans[i].s; j <= min(n,ans[i].l+ans[i].s-1); j++) 73 { 74 dp[i][j] = max(dp[i-1][j],dp[i][j]); 75 int minn = max(0,j-ans[i].l); 76 while(head<=rail) 77 { 78 ak acc = quq[head]; 79 if(acc.id < minn) 80 { 81 head++; 82 } 83 else 84 { 85 dp[i][j] = max(dp[i][j],acc.cost+j*ans[i].p); 86 break; 87 } 88 } 89 maxx = max(maxx,dp[i][j]); 90 } 91 for(j = min(n,ans[i].l+ans[i].s-1)+1; j <= n; j++) 92 { 93 dp[i][j] = dp[i-1][j]; 94 maxx = max(maxx,dp[i][j]); 95 }} 96 printf("%d\n",maxx); 97 } 98 return 0;}
标签:
原文地址:http://www.cnblogs.com/zzuli2sjy/p/5936891.html