| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 616 人关注过本帖
标题:杭电1087,为什么我错了
只看楼主 加入收藏
conquerorbzm
Rank: 2
等 级:论坛游民
帖 子:35
专家分:33
注 册:2010-7-23
结帖率:77.78%
收藏
已结贴  问题点数:20 回复次数:7 
杭电1087,为什么我错了
#include<stdio.h>
int main()
{
    int i,max,sum,j,m,d=0;
    int n;
    int a[1002];
    while(scanf("%d",&n)!=EOF&&n!=0)
    {    sum=0;max=0;m=0;d=0;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
      
        for(i=0;i<n;i++)
        {    sum=a[i];
        for(j=i+1;j<n;j++)
        {   
            if(a[i]>=a[j])
                continue;
            else a[i]=a[j];
            sum+=a[j];
        }
            if(sum>max)
                max=sum;
        
        }
            printf("%d\n",max);
    }
    return 0;
}   
2010-08-13 11:12
mxs810
Rank: 9Rank: 9Rank: 9
来 自:火星
等 级:贵宾
威 望:16
帖 子:234
专家分:1122
注 册:2006-10-19
收藏
得分:1 
要实现什么东东?

你的程序有什么问题?

授人以鱼不如授人以渔
2010-08-13 11:27
conquerorbzm
Rank: 2
等 级:论坛游民
帖 子:35
专家分:33
注 册:2010-7-23
收藏
得分:0 
这时一道简单的dp,我测试的数据都对了,但是系统显示错了。
Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HDU. Maybe you are a good boy, and know little about this game, so I introduce it to you now.





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
Input contains multiple test cases. Each test case is described in a line as follow:
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
For each case, print the maximum according to rules, and one line one case.

 

Sample Input
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
 

Sample Output
4
10
3
2010-08-13 11:43
毕业旅行
Rank: 4
等 级:业余侠客
威 望:1
帖 子:130
专家分:280
注 册:2010-7-7
收藏
得分:9 
6 1 6 2 3 4 5
算法错了,类似这个。你的循环结果应该是
1 6
6
2 3 4 5
3 4 5
4 5
5
没有1 2 3 4 5
不知道有没有看错
2010-08-13 12:24
毕业旅行
Rank: 4
等 级:业余侠客
威 望:1
帖 子:130
专家分:280
注 册:2010-7-7
收藏
得分:0 
#include <iostream>
#include <cstdio>
using namespace std;

int a[1010],sum[1010];
int main()
{
    int n;
    while(scanf("%d",&n),n)
    {
        int max=-1;
        for(int i=0;i<n;i++)
        {
            scanf("%d",a+i);
            sum[i]=a[i];
        }
        for(int i=1;i<n;i++)
        {
            for(int j=0;j<i;j++)
            {
                if(a[i]>a[j]&&a[j]+a[i]>sum[i])
                    sum[i]=sum[j]+a[i];
            }
            if(max<sum[i])
                max=sum[i];
        }
        printf("%d\n",max);
    }
    return 0;
}

看下这段代码,不是我写的,但是我仔细的看了一遍其思路,楼主也参考下吧
2010-08-13 12:27
linjx0123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:279
专家分:1362
注 册:2006-4-7
收藏
得分:10 
楼主算法错误。
这个问题,其实就是最大递增子序列问题。我是用java写的,等会我转化成c语言

[ 本帖最后由 linjx0123 于 2010-8-13 12:37 编辑 ]
2010-08-13 12:31
linjx0123
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:279
专家分:1362
注 册:2006-4-7
收藏
得分:0 
程序代码:
#include<stdio.h>

int main()
{
       int num[1002];
       int dp [1002];
       int n, i, j,max, temp;     
       while(scanf("%d",&n)!=EOF)
       {
            if(n==0)
                break;
            for (i = 1; i <= n; i++) {
                scanf("%d",&num[i]);
            }

            dp[1] = num[1];
            max = num[1];
            for (i = 2; i <= n; i++) {
                temp = 0;
                for(j =1;j<i;j++){
                    if(num[j]<num[i]){
                        if(dp[j]>temp){
                            temp = dp[j];
                        }
                    }
                }
                dp[i] = temp+num[i];
                if(dp[i]>max){
                    max=dp[i];
                }
            }
            printf("%d\n",max);
       }
       return 0;
}

代码没有经过优化,不过这个题目不需要优化也能在规定时间内完成
2010-08-13 12:34
conquerorbzm
Rank: 2
等 级:论坛游民
帖 子:35
专家分:33
注 册:2010-7-23
收藏
得分:0 
确实是算法错了,看来不能这样做啊!谢谢几位啊
2010-08-13 14:11
快速回复:杭电1087,为什么我错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013269 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved