Problem Description
An equal sum partition of a sequence of numbers is a grouping of the numbers (in the same order as the original sequence) in such a way that each group has the same sum. For example, the sequence:

2 5 1 3 3 7

may be grouped as:

(2 5) (1 3 3) (7)

to yield an equal sum of 7.



Note: The partition that puts all the numbers in a single group is an equal sum partition with the sum equal to the sum of all the numbers in the sequence.



For this problem, you will write a program that takes as input a sequence of positive integers and returns the smallest sum for an equal sum partition of the sequence.
Input
The first line of input contains a single integer
P
, (1 ≤ P ≤ 1000), which is the number of data sets that follow. The first line of each data set contains the data set number, followed by a space, followed by a decimal integer
M, (1 ≤ M ≤ 10000), giving the total number of integers in the sequence. The remaining line(s) in the dataset consist of the values, 10 per line, separated by a single space. The last line in the dataset may contain less than
10 values.
Output
For each data set, generate one line of output with the following values: The data set number as a decimal integer, a space, and the smallest sum for an equal sum partition of the sequence.
Sample Input
3
1 6
2 5 1 3 3 7
2 6
1 2 3 4 5 6
3 20
1 1 2 1 1 2 1 1 2 1
1 2 1 1 2 1 1 2 1 1
Sample Output
1 7
2 21
3 2
题意:给出一个序列,假设能把该序列分成若干段,使每段和相等,求最小和,若不能分则和为这一整序列。
#include<stdio.h>
int dp[7000][7000];
int min(int a,int b)
{
return a>b?b:a;
}
int main()
{
int a[10005],ans[10005],t,c,m;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&c,&m); ans[0]=0;
for(int i=1;i<=m;i++)
{
scanf("%d",&a[i]);
ans[i]=ans[i-1]+a[i];
}
for(int r=0;r<m;r++)
for(int i=1;i<=m-r;i++)
{
int j=i+r;
dp[i][j]=ans[j]-ans[i-1];
for(int k=i;k<j;k++)
{
if(ans[k]-ans[i-1]==dp[k+1][j])
dp[i][j]=min(dp[i][j],dp[k+1][j]);
if(dp[i][k]==ans[j]-ans[k])
dp[i][j]=min(dp[i][j],dp[i][k]);
if(dp[i][k]==dp[k+1][j])
dp[i][j]=min(dp[i][j],dp[i][k]);
}
}
printf("%d %d\n",c,dp[1][m]);
}
}

hdu3280Equal Sum Partitions (区间DP)的更多相关文章

  1. UVA - 10891 Game of Sum (区间dp)

    题意:AB两人分别拿一列n个数字,只能从左端或右端拿,不能同时从两端拿,可拿一个或多个,问在两人尽可能多拿的情况下,A最多比B多拿多少. 分析: 1.枚举先手拿的分界线,要么从左端拿,要么从右端拿,比 ...

  2. UVA 10891 Game of Sum(区间DP(记忆化搜索))

    题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...

  3. uva10891 Game of Sum(博弈+区间dp+优化)

    题目:点击打开链接 题意:两个人做游戏,共有n个数,每个人可以任选一端取任意多连续的数,问两个人都想拿最多的情况下,先手最多比后手多拿多少分数. 思路:这题一开始想到的是用dp[i][j]表示区间[i ...

  4. HDU 1231 最大连续子序列 &&HDU 1003Max Sum (区间dp问题)

    C - 最大连续子序列 Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  5. 【UVA】10891 Game of Sum(区间dp)

    题目 传送门:QWQ 分析 大力dp.用$ dp[i][j] $表示$ [i,j] $A能得到的最高分 我看到博弈论就怂... 代码 #include <bits/stdc++.h> us ...

  6. UVA - 10891 Game of Sum 区间DP

    题目连接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19461 Game of sum Description This ...

  7. E - Max Sum Plus Plus Plus HDU - 1244 (线性区间DP)

    题目大意:  值得注意的一点是题目要求的是这些子段之间的最大整数和.注意和Max Sum Plus Plus这个题目的区别. 题解: 线性区间DP,对每一段考虑取或者不取.定义状态dp[i][j]指的 ...

  8. HDU-3280 Equal Sum Partitions

    http://acm.hdu.edu.cn/showproblem.php?pid=3280 用了简单的枚举. Equal Sum Partitions Time Limit: 2000/1000 M ...

  9. 区间dp专题练习

    区间dp专题练习 题意 1.Equal Sum Partitions ? 这嘛东西,\(n^2\)自己写去 \[\ \] \[\ \] 2.You Are the One 感觉自己智力被吊打 \(dp ...

随机推荐

  1. 各种HelloWorld

    http://blog.csdn.net/whxaing2011/article/details/20736759 ES总结: http://www.cnblogs.com/sunxucool/p/3 ...

  2. C#句柄使用

    原文:C#句柄使用 调用 API 函数 SendMessage 发送 WM_CLOSE 消息. DllImport("User32.dll",EntryPoint="Se ...

  3. Dialog 顶部黑线问题

    Dialog 顶部黑线问题 样式如下: [java] view plaincopyprint? <style name="Transparent_Dialog"> &l ...

  4. warning C4133: “函数”: 从“char [5]”到“LPCWSTR”的类型不兼容

    弹窗打开一个网页,但是报错,代码如下: #include <stdio.h> #include <windows.h> void main() { ShellExecute(, ...

  5. hdu 4602 Partition(矩阵快速幂乘法)

    Problem Description Define f(n) , we have =+++ =++ =++ =++ =+ =+ =+ = totally ways. Actually, we wil ...

  6. float

    .clearfix:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: b ...

  7. Nginx 在安装入门

    1.首先需要安装必要的库,PCRE,zlib sudo apt-get install libpcre3 libpcre3-dev 假设找不到文件的话就下载源文件进行安装. 2.解压下载的nginx源 ...

  8. PHP+jQuery实现翻板抽奖

    翻板抽奖的实现流程:前端页面提供6个方块,用数字1-6依次表示6个不同的方块,当抽奖者点击6个方块中的某一块时,方块翻转到背面,显示抽奖中奖信息.看似简单的一个操作过程,却包含着WEB技术的很多知识面 ...

  9. DropDownList四级联动

    前台代码: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="iframe_dro ...

  10. Tomcat7配置数据源(Oracle)

    修改../conf/content.xml <?xml version='1.0' encoding='utf-8'?> <!-- The contents of this file ...