NYOJ 44 字串和 (最大字串和 线性dp)
题目链接:
http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=44
子串和
- 描述
- 给定一整型数列{a1,a2...,an},找出连续非空子串{ax,ax+1,...,ay},使得该子序列的和最大,其中,1<=x<=y<=n。
- 输入
- 第一行是一个整数N(N<=10)表示测试数据的组数)
每组测试数据的第一行是一个整数n表示序列中共有n个整数,随后的一行里有n个整数I(-100=<I<=100),表示数列中的所有元素。(0<n<=1000000) - 输出
- 对于每组测试数据输出和最大的连续子串的和。
- 样例输入
-
1
5
1 2 -1 3 -2 - 样例输出
-
5
- 提示
- 输入数据很多,推荐使用scanf进行输入
-
#include<bits/stdc++.h>
using namespace std;
int f_max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
int a[n+];
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
}
int dp[n+];
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
{
dp[i]=f_max(dp[i-]+a[i],a[i]);
}
int x=dp[];
for(int i=;i<=n;i++)
{
if(x<dp[i])
{
x=dp[i];
}
}
printf("%d\n",x);
}
return ;
}
NYOJ 44 字串和 (最大字串和 线性dp)的更多相关文章
- 【循环数组的最大字串和】Maximal-sum Subsequence
[循环数组的最大字串和]Maximal-sum Subsequence PROBLEM 题目描述 给一个 N×N 的矩阵 M,可以取连续的一段数(必须是横着或者竖着或者斜着,这个矩阵是循环的,具体如下 ...
- java 11-8 在大串中查找小串的案例
1.统计大串中小串出现的次数 举例: 在字符串"woaijavawozhenaijavawozhendeaijavawozhendehenaijavaxinbuxinwoaijavagun& ...
- nyoj 44
//nyoj 44 //和上面一题一样,求子串和,但是代码非常简洁..... 时间复杂度为n #include <iostream> using namespace std; int ma ...
- hdu 1711( 模式串T在主串S中首次出现的位置)
Sample Input213 51 2 1 2 3 1 2 3 1 3 2 1 21 2 3 1 313 51 2 1 2 3 1 2 3 1 3 2 1 21 2 3 2 1 Sample Out ...
- hdu3065 病毒侵袭持续中 AC自动机入门题 N(N <= 1000)个长度不大于50的模式串(保证所有的模式串都不相同), 一个长度不大于2000000的待匹配串,求模式串在待匹配串中的出现次数。
/** 题目:hdu3065 病毒侵袭持续中 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3065 题意:N(N <= 1000)个长度不大于50的 ...
- hdu2896 病毒侵袭 AC自动机入门题 N(N <= 500)个长度不大于200的模式串(保证所有的模式串都不相同), M(M <= 1000)个长度不大于10000的待匹配串,问待匹配串中有哪几个模式串,
/** 题目:hdu2896 病毒侵袭 链接:http://acm.hdu.edu.cn/showproblem.php?pid=2896 题意:N(N <= 500)个长度不大于200的模式串 ...
- 模板—字符串—KMP(单模式串,单文本串)
模板—字符串—KMP(单模式串,单文本串) Code: #include <cstdio> #include <cstring> #include <algorithm& ...
- 模板—字符串—AC自动机(多模式串,单文本串)
模板—字符串—AC自动机(多模式串,单文本串) Code: #include <queue> #include <cstdio> #include <cstring> ...
- hdu2457(最少替换多少个字符使主串不包含模式串)ac自动机+dp
题:http://acm.hdu.edu.cn/showproblem.php?pid=2457 题意:给定n个模式串,给定一个主串,问最替换掉多少个字符使主串不包含模式串或输出“-1”表示没有可行的 ...
随机推荐
- drupal7 模糊查询接口
$query->condition('card_no', db_like($batch_no).'%', 'LIKE');
- 初学PS
PS中的一些快捷键:新建:Ctrl+N 放大:Ctrl++ 缩小:Ctrl+- 首选项:Ctrl+K 标尺:Ctrl+R移动视图:空格键 绘制正圆:Shift 绘制鼠标落脚点为中心的正圆:Shift+ ...
- Visualizing CNN Layer in Keras
CNN 权重可视化 How convolutional neural networks see the world An exploration of convnet filters with Ker ...
- asp.net mvc +easyui 实现权限管理(二)
一写完后,好久没有继续写了.最近公司又在重新开发权限系统了,但是由于我人微言轻,无法阻止他们设计一个太监版的权限系统.想想确实是官大一级压死人啊, 没办法我只好不参与了 让他们去折腾. 我就大概说一下 ...
- Android 后台线程,timertask实现定期更新时间
简述:这是一类定时功能的原型,用来在后台线程中运行一些定时的服务,比如定时修改时间 知识点: 1. Android多线程的消息通信(handler) 2. Java中时间的获取,以及String的格式 ...
- GIT速成
安装工具与使用工具: GIT工具 :https://www.git-scm.com/download/ WINGDOWS图形界面工具:https://download.tortoisegit.org/ ...
- 为website安装免费的letsencrypt证书
Certbot官网:https://certbot.eff.org 1. 安装certbot命令 wget https://dl.eff.org/certbot-auto chmod a+x cert ...
- win7安装node.js
最新版本的node.js都已经集成了npm,所以直接从官网下载即可!(不用再配置环境变量) 官网:https://nodejs.org/download/release/latest/ 下载解压即安装 ...
- Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w /var/cache/app-info -a -e /usr/bin/appstreamcli; then appstreamcli refresh > /dev/null; fi'
运行sudo apt-get update 时Ubuntu 16.04出现: Problem executing scripts APT::Update::Post-Invoke-Success 'i ...
- 12.Spring——Web MVC框架
1.Spring Web MVC 框架 2.Spring MVC Hello World 例子 1.Spring Web MVC 框架 Spring web MVC 框架提供了模型-视 ...