Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

1A

Posted by 834208094 at 2013-06-11 00:02:02 on Problem 1160
过了样例就AC了
#include <iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<vector>
using namespace std;
int v, p;
int poi[600];
int dp[600][600], co[600][600];
int main()
{
    freopen("D:\\CPPProgram\\ACM\\in.txt", "r", stdin);
    scanf("%d %d", &v, &p);
    for(int i=1; i<=v; i++) scanf("%d", &poi[i]);
    memset(co, 0, sizeof co);
    for(int a=1; a<=p; a++) dp[a][a] = 0;
    for(int a=1; a<=v; a++)
    {
        for(int b=a+1; b<=v; b++)
        {
            co[a][b] = co[a][b-1] + poi[b] - poi[(a+b)/2];//此处推导出现错误浪费很多时间
            if(a == 1) dp[b][1] = co[a][b];
        }
    }
    for(int a=2; a<=v; a++)
    {
        for(int b=2; b<=p; b++)
        {
            if(b >= a) break;
            int Min = 99999999;
            for(int j=b-1; j<=a-1; j++)
            {
                if(Min>dp[j][b-1]+co[j+1][a])//之前是这么写的:co[j][a]这是不对的,因为第j个已经配对,只需往后继续找
                {
                    Min = dp[j][b-1]+co[j+1][a];
                }
            }
            dp[a][b] = Min;
        }
    }
    printf("%d\n", dp[v][p]);
    return 0;
}



Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator