一道想不出来的题
来源:互联网 发布:要成为一个编程大牛 编辑:程序博客网 时间:2024/06/11 19:36
题源·http://acm.hrbust.edu.cn/vj/index.php?c=contest-contest&cid=141#problem/5
E - Super Jumping! Jumping! Jumping!
Time Limit: 1000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
[Submit] [Status]
Description
The game can be played by two or more than two players. It consists of a chessboard(棋盘)and some chessmen(棋子), and all chessmen are marked by a positive integer or “start” or “end”. The player starts from start-point and must jumps into end-point finally. In the course of jumping, the player will visit the chessmen in the path, but everyone must jumps from one chessman to another absolutely bigger (you can assume start-point is a minimum and end-point is a maximum.). And all players cannot go backwards. One jumping can go from a chessman to next, also can go across many chessmen, and even you can straightly get to end-point from start-point. Of course you get zero point in this situation. A player is a winner if and only if he can get a bigger score according to his jumping solution. Note that your score comes from the sum of value on the chessmen in you jumping path.
Your task is to output the maximum value according to the given chessmen list.
Input
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
Output
Sample Input
3 1 3 24 1 2 3 44 3 3 2 10
Sample Output
4103
#include<stdio.h>
int main()
{
int dp[1010];
int a[1010];
int n,i,sum,sum1,j;
while(scanf("%d",&n)!=EOF)
{
if(n==0)
return 0;
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
dp[i]=0;
sum=a[0];
for(i=1;i<n;i++)
{
sum1=a[i];
for(j=0;j<i;j++)
{
if(a[i]>a[j]&&dp[i]<dp[j]+1)
{
printf("%d ",a[j]);
dp[i]=dp[i]+1;
sum1=sum1+a[j];
}
}
printf("\n%d\n",sum1);
if(sum<sum1)
{
sum=sum1;
// printf("0000");
}
}
// printf("%d %d\n",a[0],a[n-1]);
printf("%d\n",sum);
}
return 0;
}
借用求最长递增子序列,在每组求和,发现了错误
7
1 7 3 5 9 4 8
是错误的·
看了别人的代码
正确的思路
1 #include<stdio.h> 2 #include<stdlib.h> 3 #include<string.h> 4 #define MAX 1005 5 6 int main(void) 7 { 8 int n; 9 int s[MAX];10 int dp[MAX],max,ans; //dp[i]存的是以i为起点的最大升序子串的和11 12 while(scanf("%d",&n) && n)13 {14 for(int i = 0;i < n;i ++)15 scanf("%d",&s[i]);16 17 ans = dp[n - 1] = s[n - 1];18 for(int i = n - 2;i >= 0;i --) 19 {20 max = 0;21 for(int j = i + 1;j < n;j ++) //看s[i]后面哪一个子串是s[i]可以加进去的,找出所有这样的子串,取DP值最大那个22 if(s[i] < s[j] && max < dp[j])23 max = dp[j];24 dp[i] = s[i] + max;25 26 ans = ans < dp[i] ? dp[i] : ans;27 }28 ans = ans < 0 ? 0 : ans; //注意可以从起点直接跳终点,此时值为0,若是算出最终值是负数的话要选此方案29 30 printf("%d\n",ans);31 }32 33 return 0;34 }
- 一道想不出来的题
- 一道没答出来的面试题
- HDU2090 一道不提交不知道对错的题 水题
- aoj0033结题报告(想不出来看了别人的代码,基础实在差。。。)
- HDU 4345(想不出来的DP)
- 一道笔试题,生成4位不重复的整数
- 【一道不知道名字的题】AC自动机+dp
- 一道练习题引申出来的知识点(二) 正则表达式
- 全球顶尖公司的烧脑面试题,普通人一道都答不出来!
- 全球顶尖公司的烧脑面试题,普通人一道都答不出来!
- 晕,不出来不知道,天多高,不出来不知道,人与人之间的相处有多么困难?
- 一道网易Java简单集合面试题「我感觉你做不出来」
- 一道题的瞎想
- 写不出来的才是生活。
- 十个笑不出来的冷笑话
- 图片显示不出来的怪问题
- 查询出来的资料不换行
- WORD图标显示不出来的问题
- 第五周项目4-长方柱类
- String字符串比较equals遇到的坑
- 线性筛法找质数 —正确性,无重复性证明
- URL页面请求分析
- VB程序破解
- 一道想不出来的题
- 算法总结(4)希尔排序(Shell排序)
- ThinkPHP RBAC 的项目name很重要
- DP——划分子集和问题
- 《C++ Primer》 第四版 第15章 面向对象编程
- Ubuntu Linux 安装wine 和 winetricks
- 大话设计模式-建造者模式
- Android性能优化案例研究(上)
- 002 ZeroMQ PUB and SUB