Milking Time POJ 3616(基础dp)

原题

题目链接

题目分析

简单dp,很容易想到对于每个区间都只有两个选择,选和不选,因此可以定义一个dp[i],表示在前第i个区间能取得的最大奶量(区间已按起始时间排完序),注意在读入区间时可以直接在末尾时间直接加上R.更新由两个循坏来更新,第一个循环i从头区间遍历到尾区间,第二个循环j从头区间到i区间(不包括i区间),更新时要先判定是否满足cow[i].x>=cow[j].y,满足的话就更新dp[i]=max(dp[i],cow[i].efficiency+dp[j]).最后扫一遍dp数组取最大值就是答案.

代码

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <iostream>
 4 #include <algorithm>
 5 #include <utility>
 6 #include <ctime>
 7 #include <cmath>
 8 #include <cstring>
 9 #include <string>
10 #include <stack>
11 #include <queue>
12 #include <vector>
13 #include <set>
14 #include <map>
15 
16 using namespace std;
17 typedef long long LL;
18 const int INF_INT=0x3f3f3f3f;
19 const LL INF_LL=0x3f3f3f3f3f3f3f3f;
20 
21 struct P
22 {
23     int x,y,z;
24     bool operator < (const P &a)const
25     {
26         return x<a.x;
27     }
28 };
29 
30 LL dp[2000];
31 P cow[2000];
32 
33 int main()
34 {
35 //    freopen("black.in","r",stdin);
36 //    freopen("black.out","w",stdout);
37     int n,m,r;
38     cin>>n>>m>>r;
39     for(int i=1;i<=m;i++) cin>>cow[i].x>>cow[i].y>>cow[i].z,cow[i].y+=r;
40     sort(cow+1,cow+m+1);
41     for(int i=1;i<=m;i++) dp[i]=cow[i].z;
42     for(int i=1;i<=m;i++)
43     {
44         for(int j=1;j<i;j++)
45         {
46             if(cow[i].x>=cow[j].y)
47             {
48                 dp[i]=max(dp[i],cow[i].z+dp[j]);
49             }
50         }
51     }
52     LL ans=0;
53     for(int i=1;i<=m;i++) ans=max(ans,dp[i]);
54     cout<<ans<<endl;
55     return 0;
56 }

 

转载于:https://www.cnblogs.com/VBEL/p/11405287.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Based on the following story, continue the story by writing two paragraphs, paragraph 1 beginning with "A few weeks later, I went to the farm again. " and paragraph 2 beginning with "I was just about to leave when the hummingbird appeared."respectively with 150 words. I was invited to a cookout on an old friend's farm in western Washington. I parked my car outside the farm and walked past a milking house which had apparently not been used in many years.A noise at a window caught my attention,so I entered it. It was a hummingbird,desperately trying to escape. She was covered in spider-webs and was barely able to move her wings. She ceased her struggle the instant I picked her up. With the bird in my cupped hand, I looked around to see how she had gotten in. The broken window glass was the likely answer. I stuffed a piece of cloth into the hole and took her outside,closing the door securely behind me. When I opened my hand, the bird did not fly away; she sat looking at me with her bright eyes.I removed the sticky spider-webs that covered her head and wings. Still, she made no attempt to fly.Perhaps she had been struggling against the window too long and was too tired? Or too thirsty? As I carried her up the blackberry-lined path toward my car where I kept a water bottle, she began to move. I stopped, and she soon took wing but did not immediately fly away. Hovering,she approached within six inches of my face. For a very long moment,this tiny creature looked into my eyes, turning her head from side to side. Then she flew quickly out of sight. During the cookout, I told my hosts about the hummingbird incident. They promised to fix the window. As I was departing, my friends walked me to my car. I was standing by the car when a hummingbird flew to the center of our group and began hovering. She turned from person to person until she came to me. She again looked directly into my eyes, then let out a squeaking call and was gone. For a moment, all were speechless. Then someone said, “She must have come to say good-bye.”
最新发布
02-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值