[bzoj5290][Memory Search] Road

I don't want to do the problem, so the portal
is solved

The complexity of memorized search is really metaphysical. 2333
f[i][j][k] means that there are j railways and k roads on the ith city.
Blind search

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;
inline int read()
{
    int f=1,x=0;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
inline LL readx()
{
    LL f=1,x=0;char ch=getchar();
    while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0' && ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
LL f[21000][45][45],ans;
int s[21000],t[21000];
LL C[21000],A[21000],B[21000];
LL dfs(int x,int u,int v)//公 铁 
{
    if(x<0)return C[abs(x)]*(A[abs(x)]+u)*(B[abs(x)]+v);
    if(f[x][u][v]!=-1)return f[x][u][v];
    LL cnt=0;
    cnt+=dfs(s[x],u,v);//翻修公路 
    cnt+=dfs(t[x],u,v+1);
    f[x][u][v]=cnt;cnt=0;
    cnt+=dfs(t[x],u,v);
    cnt+=dfs(s[x],u+1,v);
    f[x][u][v]=min(f[x][u][v],cnt);
    return f[x][u][v];
}
int n;
int main()
{
    //freopen("road.in","r",stdin);
//  freopen("road.out","w",stdout);
    n=read();
    for(int i=1;i<n;i++)s[i]=read(),t[i]=read();
    for(int i=1;i<=n;i++)A[i]=readx(),B[i]=readx(),C[i]=readx();
    memset(f,-1,sizeof(f));
    dfs(1,0,0);
    printf("%lld\n",f[1][0][0]);
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324782165&siteId=291194637