Sicily 11600. Pick It
来源:互联网 发布:rds mysql 慢 编辑:程序博客网 时间:2024/06/05 10:23
11600. Pick It
Constraints
Time Limit: 5 secs, Memory Limit: 256 MB
Description
You are playing a game of Pick It. You are given a list of positive integers, and you are allowed to select any number other than the first or last number in this list. When you pick a number, that number is removed from the board, and your score increases by the sum of the number that you picked and the sum of the neighbouring numbers.
For example, if the list contained 1 2 3 4 5, and you picked 3, your score would be2+3+4=9. On the next turn, your list would be 1 2 4 5, and if you picked 4 next, your score would be 9+2+4+5 = 20, leaving you with the list 1 2 5. The game concludes when there are only two numbers remaining.
Given a list of numbers, what is the maximum score that you can obtain?
Input
The input will consist of a number of test cases (at most 200 test cases). A test case is of the form n k1 k2 ... kn where n (n ≤ 200) is the number of numbers in the list, and each integer ki satisfies 1 ≤ ki ≤ 100). In all test cases n ≥ 3, except in the case where n=0, which indicates the end of input.
Output
For each test case, output the maximum score attainable.
Sample Input
5 1 2 3 4 55 2 1 5 3 46 30 20 40 50 70 600
Sample Output
3031570
Problem Source
2014年每周一赛第八场
http://blog.csdn.net/gwq5210/article/details/40949033
// Problem#: 11600// Submission#: 3550130// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include <stdio.h>#include <string.h>unsigned short dp[200][200], w[200], N;inline int max(int a, int b) {if (a > b) return a; return b;}int main() { while (scanf("%d", &N) && N) { for (int i = 0; i < N; i++) scanf("%d", w + i); N--; memset(dp, 0, sizeof(dp)); for (int i = 1; i < N; i++) for (int j = 1; j + i <= N; j++) for (int k = j; k < j + i; k++) dp[j][j + i] = max(dp[j][j + i], dp[j][k] + dp[k + 1][j + i] + w[j - 1] + w[k] + w[j + i]); printf("%d\n", dp[1][N]); } return 0;}
- Sicily 11600. Pick It
- Sicily 1158. Pick numbers
- Sicily 1158 Pick numbers
- sicily 1158.Pick numbers
- Sicily 1158 Pick numbers
- Sicily 1258. It
- Sicily 1923. Is It Nim?
- Sicily 1797. Do solve it directly
- Sicily 1797. Do solve it directly
- Sicily 1797. Do solve it directly
- Sicily 1634. Relax! It's just a game
- pick公式
- Pick原理
- pick 定理
- Pick apples
- Pick Apples
- Pick Game
- Pick numbers
- VirtualBOX 虚拟机安装 OS X 10.9 Mavericks 及 Xcode 5,本人X220亲测
- git常用命令
- .aspx页面在低版本ie下文档模式自动为“杂项(Quirks)”导致页面变样的问题
- 指针函数和函数指针
- VMware内存分配初探
- Sicily 11600. Pick It
- java读取 *.properties文件
- 动态分配二维数组
- css3中webkit-box的用法
- C++STL 常用 函数 用法
- 计算机中的数学
- Next Permutation
- servlet/filter/listener/interceptor区别与联系
- Libgdx TexturePacker大图分割为小图