Max Sum(hd P1003)
#include<stdio.h>
int main()
{
int a[],T,N,T1,j,i;
scanf("%d",&T);
T1=T;
while(T--)
{
int Msum=,sum=,s=,w=;
printf("case %d:\n",T1-T);
scanf("%d",&N);
for(i=;i<N;i++)
scanf("%d",&a[i]);
Msum=a[];
for(j=;j<N;j++)
{
for(i=j;i<N;i++)
{
if(a[i]<=)
{
sum+=a[i];
continue;
}
sum+=a[i];
if(Msum<sum)
{
s=j;
w=i;
Msum=sum;
}
}
sum=;
}
printf("%d %d %d\n\n",Msum,s+,w+);
}
return ;
}
/*状态转移方程 d[i] = max(d[i-1]+a[i], a[i])
d[i]表示以i位置结束的最大子序列之和。*/
#include<stdio.h>
int main()
{
int a[];
int T,T1;
scanf("%d",&T);
T1=T;
while(T--)
{
int sum=,msum=,i,x=,y=,start=,end=,N;
scanf("%d",&N);
for(i=;i<N;i++)
scanf("%d",&a[i]);
sum=a[];
msum=sum;
for(i=;i<N;i++)
{
if(sum<)/*dp[i-1]对a[i]不仅没有贡献,反而有损害,就应该舍弃*/
{
x=y=i;
sum=a[i];
}
else
{
sum+=a[i];
y=i;
}
if(sum>msum)
{
msum=sum;
start=x;
end=y;
}
}
printf("Case %d:\n",T1-T); if(T==)
printf("%d %d %d\n",msum,start+,end+);
else
printf("%d %d %d\n\n",msum,start+,end+); }
}
Max Sum(hd P1003)的更多相关文章
- [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K
Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...
- 2016huasacm暑假集训训练五 J - Max Sum
题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/J 题意:求一段子的连续最大和,只要每个数都大于0 那么就会一直增加,所以只要和0 ...
- Max Sum
Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum of a sub ...
- HDU 1024 max sum plus
A - Max Sum Plus Plus Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- hdu 1024 Max Sum Plus Plus
Max Sum Plus Plus Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- hdu 1003 MAX SUM 简单的dp,测试样例之间输出空行
测试样例之间输出空行,if(t>0) cout<<endl; 这样出最后一组测试样例之外,其它么每组测试样例之后都会输出一个空行. dp[i]表示以a[i]结尾的最大值,则:dp[i ...
- Max Sum Plus Plus——A
A. Max Sum Plus Plus Now I think you have got an AC in Ignatius.L's "Max Sum" problem. To ...
- hdu 1003 Max sum(简单DP)
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem ...
- HDU 1003 Max Sum
Max Sum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
随机推荐
- ajax创建对象
<script> function createAjax(){ var request=false; //window对象中有X ...
- python笔记之ZipFile模块
python笔记之ZipFile模块 zipfile模块用来做zip格式编码的压缩和解压缩的,zipfile里有两个非常重要的class, 分别是ZipFile和ZipInfo, 在绝大多数的情况下, ...
- 基于方法的LINQ语句
LINQ中的查询方法有两站,一种是使用类似于SQL语句的方式,另一种则是基于方法的语句.基于方法的查询方法使用的是C#中面向对象概念的,主要的方法有: 投影: Select | SelectMany ...
- SqlServer IF Exists([database]|[table]|[prop]) / Column([Operation])
*************************** --判断数据库是否存在 IF EXISTS (SELECT * FROM MASTER..sysdatabases WHERE NAME = ' ...
- cf478A Initial Bet
A. Initial Bet time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- Add and Search Word - Data structure design 解答
Question Design a data structure that supports the following two operations: void addWord(word) bool ...
- openstack configure
<一,nova.conf配置文件配置 hypervisors compute_driver = 值> 1,kvm/qemu Hypervisor OpenStack nova comput ...
- Linux开机禁用开启防火墙
1.# chkconfig --list:显示开机可以自动启动的服务 结果:iptables 0:off 1:off 2:on 3:on 4:on 5:on ...
- magento后台登陆后,没任何提示,又跳转到登陆页面
这个问题通常是cookie配置的问题.需要去将core_config_data中web/cookie/cookie_path.web/cookie/cookie_domain设为null
- Unity 人物跟谁手指的移动(第一种方式)
长夜漫漫无心睡眠,敲敲代码,越敲越来劲! 我发现好多小朋友都在玩熊出没之xxxx这个游戏,居然打了一下午都没玩通第2关,我把测试也叫来陪我一起玩! 结果他也打不通,我再去叫策划,他也没打过,我去叫主管 ...