poj 1738 An old Stone Game(区间dp 合并石子问题直线型)
来源:互联网 发布:windows update不更新 编辑:程序博客网 时间:2024/05/02 00:59
1、http://poj.org/problem?id=1738
参考百度文库:http://wenku.baidu.com/view/adac87bbfd0a79563c1e726a.html
2、
An old Stone Game
Time Limit: 5000MS Memory Limit: 30000KTotal Submissions: 2278 Accepted: 543
Description
There is an old stone game.At the beginning of the game the player picks n(1<=n<=50000) piles of stones in a line. The goal is to merge the stones in one pile observing the following rules:
At each step of the game,the player can merge two adjoining piles to a new pile.The score is the number of stones in the new pile.
You are to write a program to determine the minimum of the total score.
At each step of the game,the player can merge two adjoining piles to a new pile.The score is the number of stones in the new pile.
You are to write a program to determine the minimum of the total score.
Input
The input contains several test cases. The first line of each test case contains an integer n, denoting the number of piles. The following n integers describe the number of stones in each pile at the beginning of the game.
The last test case is followed by one zero.
The last test case is followed by one zero.
Output
For each test case output the answer on a single line.You may assume the answer will not exceed 1000000000.
Sample Input
110033 4 341 1 1 10
Sample Output
0178
3、wrong 代码:
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define N 50005#define MAX 0x7fffffffint stone[N];int sum[N];int dp[N][N];int main(){ int n,add; while(scanf("%d",&n)!=EOF) { if(n==0) break; for(int i=0; i<n; i++) scanf("%d",&stone[i]); sum[0]=stone[0]; for(int i=1;i<n;i++) { sum[i]=sum[i-1]+stone[i]; } for(int i=0;i<n;i++) dp[i][i]=0; for(int v=1;v<n;v++) { for(int i=0;i<n-v;i++) { int j=i+v; dp[i][j]=MAX; if(i>0) add=sum[j]-sum[i-1]; else add=sum[j]; for(int k=i;k<j;k++) { dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+add); } } } printf("%d\n",dp[0][n-1]); } return 0;}
- poj 1738 An old Stone Game(区间dp 合并石子问题直线型)
- POJ 1738 An old Stone Game 石子合并之GarsiaWachs算法
- POJ 1738:An old Stone Game 石子归并(GarsiaWachs算法)
- [GarsiaWachs算法] BZOJ 3229 [Sdoi2008]石子合并 & POJ 1738 An old Stone Game & 51Nod 1023 石子归并 V3
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- poj1738 An old Stone Game 石子合并(归并) GarsiaWachs算法
- POJ 1738 An old Stone Game 笔记
- poj 1738 An old Stone Game(此题数小则可用区间DP,数较大用一维数组或者GarsiaWachs算法),待续
- poj 1694 An Old Stone Game 树形dp
- POJ 1694 An Old Stone Game
- POJ 1694 An Old Stone Game
- POJ--1694--An Old Stone Game
- poj 1694 An old stone game
- POJ 1694 An Old Stone Game 笔记
- poj 1738 石子合并(区间DP)
- 石子合并 动态规划(直线型)
- 石子合并_直线型 动态规划
- 【原创】国庆PE总复习(三)
- C# 子窗体中调用父窗体中的方法(或多窗体之间方法调用)
- Linux配置文件介绍
- uva10954 - Add All
- 在blackberry中载入图片使其在屏幕上显示的方法以及二维图形的绘制
- poj 1738 An old Stone Game(区间dp 合并石子问题直线型)
- 我的Java开发学习之旅------>Java ClassLoader解析一(转)
- java 时间转换
- Excel VBA用户窗体常用的方法
- Customising the Pentaho User Console (PUC)
- android 调用draw(canvas) 函数自动退出
- 如何使用 epoll? 一个 C 语言实例
- 国外黑客们的入侵网站思路
- 用ksoap2-android 访问webservice设置超时的问题