首页 > 其他 > 详细

hdu_5783_Divide the Sequence(贪心)

时间:2016-08-02 20:53:20      阅读:144      评论:0      收藏:0      [点我收藏+]

题目链接:hdu_5783_Divide the Sequence

题意:

给你一个数列,让你分尽可能多的段,并且保证每一段的前缀和都不小于0

题解:

从后往前xjb贪心就行了

技术分享
 1 #include<cstdio>
 2 
 3 const int N=1e6+7;
 4 int a[N];
 5 int main()
 6 {
 7     int n;
 8     while(~scanf("%d",&n))
 9     {
10         for(int i=1;i<=n;i++)scanf("%d",a+i);
11         long long sum=0,ans=0;
12         for(int i=n;i>=1;i--)
13         {
14             sum+=a[i];
15             if(sum>=0)ans++,sum=0;
16         }
17         printf("%lld\n",ans);
18     }
19     return 0;
20 }
View Code

 

hdu_5783_Divide the Sequence(贪心)

原文:http://www.cnblogs.com/bin-gege/p/5730544.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!