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

小小的优化了一下~

Posted by Moon_1st at 2011-02-01 10:18:25 on Problem 1157
开始写了个f*v^2的,然后发现实际上f*v就够了~
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

const int N = 101;
const int INF = -65536;

int n, m, v[N][N], f[N][N];

int Max(int x, int y)
{
    return x > y ? x : y;
}

int main()
{
    int i, j, ans = INF;
    scanf("%d%d", &n, &m);
    for(i = 1; i <= n; i++)
        for(j = 1; j <= m; j++)
            scanf("%d", &v[i][j]);
    memset(f, 0, sizeof(f));
    for(j = 1; j <= m; j++)
        for(i = 1; i <= j; i++)
        {
            f[j][i] = INF;
            if(j > i)  f[j][i] = f[j-1][i];
            f[j][i] = Max(f[j][i], f[j-1][i-1]+v[i][j]);
        }
    for(i = n; i <= m; i++)  ans = Max(ans, f[i][n]);
    printf("%d\n", ans);
    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