hdu 4223 Dynamic Programming?
Dynamic Programming?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Ok, here is the problem. Given an array with N integers, find a continuous subsequence whose sum’s absolute value is the smallest. Very typical DP problem, right?
Each test case includes an integer N. Then a line with N integers Ai follows.
Technical Specification
1. 1 <= T <= 100
2. 1 <= N <= 1 000
3. -100 000 <= Ai <= 100 000
2
1 -1
4
1 2 1 -2
Case 2: 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=4e6+,inf=1e9+,mod=1e9+;
const ll INF=1e18+;
int a[N];
int pre[N];
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++)
pre[i]=pre[i-]+a[i];
int ans=inf;
for(int i=;i<=n;i++)
for(int t=i;t<=n;t++)
{
ans=min(ans,abs(pre[t]-pre[i-]));
}
printf("Case %d: %d\n",cas++,ans);
}
return ;
}
hdu 4223 Dynamic Programming?的更多相关文章
- HDU 4223 Dynamic Programming?(最小连续子序列和的绝对值O(NlogN))
传送门 Description Dynamic Programming, short for DP, is the favorite of iSea. It is a method for solvi ...
- hdu 4223 Dynamic Programming? (dp)
//连续的和的绝对值最小 # include <stdio.h> # include <string.h> # include <algorithm> # incl ...
- hdu分类 Dynamic Programming(这是一场漫长的旅途)
下面是difficulty 1的题 1003 Max Sum 最长递增子序列.非常经典,最棒的解法是在线算法O(n)的复杂度. 贴的呢,是用dp做的代码. 先是一个高亮的dp递推式,然后找到最大处 ...
- hdu 4972 A simple dynamic programming problem(高效)
pid=4972" target="_blank" style="">题目链接:hdu 4972 A simple dynamic progra ...
- HDU-4972 A simple dynamic programming problem
http://acm.hdu.edu.cn/showproblem.php?pid=4972 ++和+1还是有区别的,不可大意. A simple dynamic programming proble ...
- 动态规划 Dynamic Programming
March 26, 2013 作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: ...
- Dynamic Programming
We began our study of algorithmic techniques with greedy algorithms, which in some sense form the mo ...
- hdu 4223
暴力: Problem : ( Dynamic Programming? ) Judge Status : Accepted RunId : Language : C++ Author : yudun ...
- 算法导论学习-Dynamic Programming
转载自:http://blog.csdn.net/speedme/article/details/24231197 1. 什么是动态规划 ------------------------------- ...
随机推荐
- vsftp不同帐号的目录和权限
搭建FTP服务器,供虚拟用户使用,实现不同用户具有不同家目录和权限. 1.用户peter的家目录为/var/ftp/vuserdir/peter,他只有下载权限,没有其他权限(创建目录.重命名.删除. ...
- Python 的命令行参数处理 optparse->argparse
optaprse自2.7版开始弃用:弃用optparse模块,不会进一步开发,将继续开发argparse模块作为替代. 但是用习惯了optparse,还是很好用的撒. optparse使用起来,相比旧 ...
- Environment中针对的读写权限判断
Android应用开发中,常使用Environment类去获取外部存储目录,在访问外部存储之前一定要先判断外部存储是否已经是可使用(已挂载&可使用)状态,并且需要在AndroidManifes ...
- https笔记
TCP提供了可靠的,面向连接的字节流服务. 1)应用数据分割成TCP认为适合发送的数据块,通过MSS(最大数据包长度)来控制. 2)重传机制 3)对首部和数据进行校验 4)TCP对收到的数据进行排序, ...
- MEANIO
sudo npm install -g bower sudo npm install -g meanio sudo bower cache clean --allow-root sudo mean i ...
- PHP的数据类型、常量、时间
[数据类型之间相互转换] ◆ 一种是强制转换: setType( 变量, 类型); // 类型 int, integer, float, double,real, bool, boolena, st ...
- myeclipse的快捷键和myeclipse快捷键设置
1.Ctrl+M切换窗口的大小 2.Ctrl+Q跳到最后一次的编辑处 3.F2当鼠标放在一个标记处出现Tooltip时候按F2则把鼠标移开时Tooltip还会显示即Show Tooltip D ...
- YTU 3008: 链串的基本运算
3008: 链串的基本运算 时间限制: 1 Sec 内存限制: 128 MB 提交: 1 解决: 1 题目描述 编写一个程序,实现链串的各种基本运算,主函数已给出,请补充每一种方法. 1.建立串s ...
- js判断radio,checkbox是否选中
从数据库循环数据,多选按钮数组 function type_1(){ //多选 var b= document.getElementsByName('service_zj_ids[]'); var ...
- IIS装好后,局域网不能访问
IIS默认安装完成后,可以通过http:\\localhost或http:\\127.0.0.1或者http:\\ip地址访问,但是局域网内却不能通过IP来访问,通常只需要将防火墙关掉就好了,也在在防 ...