救救孩子!

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

kIG7Z8oP @ 2019-10-30 19:14:53

数字三角型写死了QwQ

#include<cstdio>
#include<cstring>
int map[1010][1010],ans[1010][1010],n;
int max(int a,int b)
{
    return a>b?a:b;
}
int dp(int x,int y)
{
    if(~ans[x][y]) return ans[x][y];
    ans[x][y]=map[x][y];
    if(x==n) return ans[x][y];
    ans[x][y]+=max(dp(x+1,y),y==x?-123456:dp(x+1,y+1));
    return ans[x][y];
}
inline int read()
{
    int x=0;
    char c=getchar();
    while(c>57||c<48) c=getchar();
    while(c>47&&c<58) x=(x<<3)+(x<<1)+(c&15),c=getchar();
    return x;
}
int main()
{
    memset(ans,-1,sizeof(ans));
    n=read();
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
            map[i][j]=read();
    printf("%d",dp(1,1));
}

by kIG7Z8oP @ 2019-10-30 19:16:35

56分


by sc84bbs @ 2019-10-30 19:20:54

stO 暴切IOI神犇


by Lupus @ 2019-10-30 19:22:25

sto lz爆kIOI。。


by 一梦南柯 @ 2019-10-30 19:30:22

你递推不行吗...

多层函数递归很慢的


by 一梦南柯 @ 2019-10-30 19:30:28

@kIG7Z8oP


|