| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
小小的优化了一下~开始写了个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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator