http://acm.fzu.edu.cn/problem.php?pid=2177

Problem 2177 ytaaa

Accept: 113    Submit: 265
Time Limit: 2000 mSec    Memory Limit : 32768 KB

 Problem Description

Ytaaa作为一名特工执行了无数困难的任务,这一次ytaaa收到命令,需要炸毁敌人的一个工厂,为此ytaaa需要制造一批炸弹以供使用。 Ytaaa使用的这种新型炸弹由若干个炸药组成,每个炸药都有它的威力值,而炸弹的威力值为组成这个炸弹的所有炸药的最大威力差的平方,即(max-min)^2,假设一个炸弹有5个炸药组成,威力分别为5 9 8 2 1,那么它的威力为(9-1)^2=64。现在在炸弹的制造流水线上已经有一行n个炸药,由于时间紧迫,ytaaa并没有时间改变它们的顺序,只能确定他们的分组。作为ytaaa的首席顾问,请你帮助ytaaa确定炸药的分组,使制造出的炸弹拥有最大的威力和。

 Input

输入由多组数据组成。第一行为一个正整数n(n<=1000),第二行为n个数,第i个数a[i]为第i个炸药的威力值(0<=a[i]<=1000)。

 Output

对于给定的输入,输出一行一个数,为所有炸弹的最大威力和。

 Sample Input

6
5 9 8 2 1 6

 Sample Output

77
 
 
分析:
 
一开始没有看懂题, 以为样例错啦(服了我啦),后来知道是分开几组计算的。
 动规可解:dp[i]表示前i个炸药能组成的最大威力和。
状态转移方程:dp[i]=max(dp[i],dp[j-1]+(a[i]-a[j])^2)。
 
AC代码:
 
 #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <list>
#include <iomanip>
#include <vector>
#pragma comment(linker, "/STACK:1024000000,1024000000")
#pragma warning(disable:4786) using namespace std; const int INF = 0x3f3f3f3f;
const int MAX = + ;
const double eps = 1e-;
const double PI = acos(-1.0); int dp[MAX];
int a[MAX]; int main()
{
int n;
while(~scanf("%d",&n))
{
int i , j;
for(i = ;i <= n;i ++)
scanf("%d",&a[i]);
memset(dp , , sizeof(dp));
for(i = ;i <= n;i ++)
for(j = i;j >= ;j --)
dp[i] = max(dp[i] , dp[j - ] + (a[i] - a[j]) * (a[i] - a[j]));
printf("%d\n",dp[n]);
}
return ;
}
 

fzuoj Problem 2177 ytaaa的更多相关文章

  1. fzuoj Problem 2129 子序列个数

    http://acm.fzu.edu.cn/problem.php?pid=2129 Problem 2129 子序列个数 Accept: 162    Submit: 491Time Limit: ...

  2. fzuoj Problem 2179 chriswho

    http://acm.fzu.edu.cn/problem.php?pid=2179 Problem 2179 chriswho Accept: 57    Submit: 136 Time Limi ...

  3. fzuoj Problem 2182 水题

    http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188    Submit: 277Time Limit: 100 ...

  4. FZUOJ Problem 2178 礼品配送

    Problem 2178 礼物分配 题目链接: Click Here~ Problem Description 在双胞胎兄弟Eric与R.W的生日会上,他们共收到了N个礼物,生日过后他们决定分配这N个 ...

  5. FZUOJ Problem 2200 cleaning DP

    Problem 2200 cleaning  Problem Description N个人围成一圈在讨论大扫除的事情,需要选出K个人.但是每个人与他距离为2的人存在矛盾,所以这K个人中任意两个人的距 ...

  6. ZCMU 2177 Lucky Numbers (easy)

    传送门: http://acm.zcmu.edu.cn/JudgeOnline/problem.php?id=2177 2177: Lucky Numbers (easy) 时间限制: 2 Sec   ...

  7. FZU2177——ytaaa——————【区间dp】

     ytaaa Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  8. Problem 2238 Daxia & Wzc's problem 1627 瞬间移动

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 http://acm.fzu.edu.cn/problem.php ...

  9. 【hdu 2177】取(2堆)石子游戏

    Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

随机推荐

  1. SQL优化(zhuan)

    转自:http://www.jfox.info/SQL-you-hua 数据库的优化问题 一.问题的提出 在应用系统开发初期,由于开发数据库数据比较少,对于查询SQL语句,复杂视图的的编写等体会不出S ...

  2. Java保留两位小数的几种做法

    1.  String类型数字始终保留两位小数 , RoundingMode.HALF_UP); return bd.toString(); } /** * 使用DecimalFormat,保留小数点后 ...

  3. jquery_easyui的使用

    一.引入jquery,jquery_easyui,jquery_easyui css,图标css,本地语言 二.通过学习jquery_easyui 手册,用简单的js代码来实现(按钮.表单.表格.弹出 ...

  4. 国外it网站收集

    1.http://news.com.com/2.http://www.zdnet.com/3.http://www.salon.com/tech/index.html4.http://www.brin ...

  5. MongoDB非正常关闭后修复记录

    启动mongodb时出现如下错误: 根据提示可以知道错误原因是mongodb非正常关闭,此时需要对数据库进行修复.修复命令:mongod --repair 或 ./mongod --repair , ...

  6. 几个简单的html+css+js题目

    1.页面中有一图片,请在下划线处添加代码能够实现隐藏该图片的功能 <img id="pic" src="door.jpg" width="200 ...

  7. [LeetCode] Search for a Range(二分法)

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  8. ASP.NET MVC 利用ActionFilterAttribute来做权限等

    ActionFilterAttribute是Action过滤类,该属于会在执行一个action之前先执行.而ActionFilterAttribute是 MVC的一个专门处理action过滤的类.基于 ...

  9. A Word (Or Two) On Quality

    In the world of interactive project management the promise of quality has become cliché. Quality is ...

  10. sql 显示0001