poj 1651 http://poj.org/problem?id=1651
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6188 | Accepted: 3777 |
Description
The goal is to take cards in such order as to minimize the total number of scored points.
For example, if cards in the row contain numbers 10 1 50 20 5, player might take a card with 1, then 20 and 50, scoring
10*1*50 + 50*20*5 + 10*50*5 = 500+5000+2500 = 8000
If he would take the cards in the opposite order, i.e. 50, then 20, then 1, the score would be
1*50*20 + 1*20*5 + 10*1*5 = 1000+100+50 = 1150.
Input
Output
Sample Input
6
10 1 50 50 20 5
Sample Output
3650
题意:
从中间选择一个数乘以左右俩边的数,第一个和最后一个不能选择,这个数就拿出来,怎样拿出来的顺序,使总和最小。
分析:abc sum=a*b*c;
abcd sum1=abc+acd;
sum2=bcd+abd;
sum=min(sum1,sum2)
dp[i][j]=min(dp[i][j],a[i]*a[g]*a[j]+dp[i][g]+dp[g][j]);(i<g<j)
也就是说igj,向该数列插入数字,是i和g之间或者是g和i之间。
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int dp[][];
int main()
{
int i,j,k,n,a[],g;
while(~scanf("%d",&n))
{
memset(dp,,sizeof(dp));
for(i=;i<n;i++)
scanf("%d",&a[i]);
for(k=;k<n;k++)//保证最小有3位数。
{
for(i=;i<n-k;i++)
{
j=i+k;
dp[i][j]=;//求最小,初始化最大。
for(g=i+;g<j;g++)
dp[i][j]=min(dp[i][j],a[i]*a[g]*a[j]+dp[i][g]+dp[g][j]);
}
} printf("%d\n",dp[][n-]);
}
return ;
}
/*
6
10 1 50 50 20 5
3650
*/
poj 1651 http://poj.org/problem?id=1651的更多相关文章
- poj-3056 http://poj.org/problem?id=3056
http://poj.org/problem?id=3056 The Bavarian Beer Party Time Limit: 6000MS Memory Limit: 65536K Tot ...
- poj 1679 http://poj.org/problem?id=1679
http://poj.org/problem?id=1679 The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submis ...
- POJ3278http://poj.org/problem?id=3278
http://poj.org/problem?id=3278 题目大意: m,n两个数m可+1, -1, *2变成n,需要经过几步 #include<stdio.h> #include&l ...
- OpenJudge/Poj 1207 The 3n + 1 problem
1.链接地址: http://bailian.openjudge.cn/practice/1207/ http://poj.org/problem?id=1207 2.题目: 总时间限制: 1000m ...
- POJ 3320 Jessica‘s Reading Problem(哈希、尺取法)
http://poj.org/problem?id=3320 题意:给出一串数字,要求包含所有数字的最短长度. 思路: 哈希一直不是很会用,这道题也是参考了别人的代码,想了很久. #include&l ...
- poj 1681 Painter's Problem(高斯消元)
id=1681">http://poj.org/problem? id=1681 求最少经过的步数使得输入的矩阵全变为y. 思路:高斯消元求出自由变元.然后枚举自由变元,求出最优值. ...
- POJ 3100 Root of the Problem || 1004 Financial Management 洪水!!!
水两发去建模,晚饭吃跟没吃似的,吃完没感觉啊. ---------------------------分割线"水过....."--------------------------- ...
- <挑战程序设计竞赛> poj 3320 Jessica's Reading Problem 双指针
地址 http://poj.org/problem?id=3320 解答 使用双指针 在指针范围内是否达到要求 若不足要求则从右进行拓展 若满足要求则从左缩减区域 代码如下 正确性调整了几次 然后 ...
- 尺取法 POJ 3320 Jessica's Reading Problem
题目传送门 /* 尺取法:先求出不同知识点的总个数tot,然后以获得知识点的个数作为界限, 更新最小值 */ #include <cstdio> #include <cmath> ...
随机推荐
- CTSC2016&&APIO2016游记
4.30 下午衡中放假,我们因为比赛的缘故提前到中午12:00放假 然后我爸爸说要来接我,直到下午两点多他才到,然后衡中宿舍的楼管阿姨死活不给我开门 莫名其妙的等到了三点多快四点的时候我才跟实验班的一 ...
- ubuntu 修改主机及主机名
修改主机: sudo vim /etc/hostname sudo vim /etc/hosts 修改用户名: sudo vim /etc/passwd sudo mv /home/yinggc /h ...
- JAVA! static什么作用?
是静态修饰符,什么叫静态修饰符呢?大家都知道,在程序中任何变量或者代码都是在编译时由系统自动分配内存来存储的,而所谓静态就是指在编译后所分配的内存会一直存在,直到程序退出内存才会释放这个空间,也就是只 ...
- PHP裁剪图片
PHP裁剪图片 $src_path = '1.jpg'; //创建源图的实例 $src = imagecreatefromstring(file_get_contents($src_path)); / ...
- NSArray 利用数组创建数组
NSArray *array=[NSArray arrayWithObjects:@"1",@"2",@"3", nil]; ...
- swift:类型转换(is用作判断检测、as用作类型向下转换)
类型转换是一种检查类实例的方式,并且哦或者也是让实例作为它的父类或者子类的一种方式. 类型转换在Swift中使用is 和 as操作符实现.这两个操作符提供了一种简单达意的方式去检查值的类型或者转换 ...
- hadoop拾遗(二)---- 文件模式
在单个操作中处理一批文件,这是一个常见的要求.举例来说,处理日志的MapReduce作业可能需要分析一个月内包含在大量目录中的日志文件.在一个表达式中使用通配符来匹配多个文件是比较方便的,无需列举第个 ...
- Linux改IP后务必重启网络服务
[root@localhost ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0BOOTPROTO=noneONBOOT=yes ...
- R: count number of distinct values in a vector
numbers <- c(4,23,4,23,5,43,54,56,657,67,67,435, 453,435,324,34,456,56,567,65,34,435) a & ...
- dom4j修改,获取,增加xml中某个元素的属性值
XML文件: <?xml version="1.0" encoding="UTF-8"?> <vrvscript> <item I ...