WA55分,用dp做的

P1216 [USACO1.5] [IOI1994]数字三角形 Number Triangles

Tyler0819 @ 2020-04-10 23:16:03

#include <iostream>
#include <algorithm>
using namespace std;
int r,sum;
int n = 1;
int num[1005][1005];
int f[1005][1005];
int main()
{
    cin >> r;
    for(int i = 1; i <= r; i++)
    {
        n++;
        for(int j = 1; j <= n; j++)
        {
            int k;
            cin >> k;
            num[i][j] = k;
        }
    }
    f[1][1] = num[1][1];
    for(int i = 1; i <= r; i++)
    {
        for(int j = 1; j <= i; j++)
        {
            f[i][j] = max(f[i - 1][j - 1], f[i - 1][j]) + num[i][j];
        }
    }
    for(int i = 1; i <= n; i++)
    {
        sum = max(f[r][i], sum);
    }
    cout << sum << endl;
    return 0;
}

by Tyler0819 @ 2020-04-10 23:52:13

hello?有人吗?


|