谁能告诉我为什么空间开不到1024MB

P4383 [八省联考 2018] 林克卡特树

![](https://cdn.luogu.com.cn/upload/pic/17170.png)
by ysner @ 2018-04-09 21:57:14


代码开空间部分 ``` const int N=3e5+5; int n,k,h[N],cnt,f[3][N][105]; struct Edge { int to,next,w; }e[N<<1]; ```
by ysner @ 2018-04-09 21:58:21


Update:f是long long类型
by ysner @ 2018-04-09 21:59:03


@[ysner](/space/show?uid=21534) 有没有用指针啊?
by Anguei @ 2018-04-09 21:59:20


@[yyfcpp](/space/show?uid=53062) 没啊 ``` il void dfs(re int u,re int fa) { f[0][u][0]=f[1][u][0]=f[2][u][0]=0; for(re int i=h[u];i+1;i=e[i].next) { re int v=e[i].to; if(v==fa) continue; dfs(v,u); fq(j,k,1) { f[1][u][j]=max(f[1][u][j],f[0][u][j]+f[1][v][0]+e[i].w); fq(o,j-1,0) { f[0][u][j]=max(f[0][u][j],f[0][u][o]+f[0][v][j-o]); f[1][u][j]=max(f[1][u][j],max(f[0][u][o]+f[1][v][j-o]+e[i].w,f[1][u][o]+f[0][v][j-o])); f[2][u][j]=max(f[2][u][j],max(f[1][u][o]+f[1][v][j-o-1]+e[i].w,f[2][u][o]+f[0][v][j-o])); } } f[1][u][0]=max(f[1][u][0],f[1][v][0]+e[i].w); } f[0][u][1]=max(0,f[0][u][1]); fp(i,1,k) f[0][u][i]=max(f[0][u][i],max(f[1][u][i-1],f[2][u][i])); } int main() { freopen("lct.in","r",stdin); freopen("lct.out","w",stdout); memset(h,-1,sizeof(h)); n=gi();k=gi(); fp(i,1,n-1) { re int u=gi(),v=gi(),w=gi(); add(u,v,w);add(v,u,w); } memset(f,-63,sizeof(f)); k++;dfs(1,0); printf("%d\n",f[0][1][k]); fclose(stdin); fclose(stdout); return 0; } ```
by ysner @ 2018-04-09 22:00:05


@[ysner](/space/show?uid=21534) 好像有时候如果注释掉 freopen 会 RE? 实在不行动态开数组?
by Anguei @ 2018-04-09 22:06:18


@[yyfcpp](/space/show?uid=53062) 意思是注释掉 freopen 但不删掉
by Anguei @ 2018-04-09 22:06:53


@[yyfcpp](/space/show?uid=53062) 试了一下,不是这个问题
by ysner @ 2018-04-09 22:35:06


Win msvc2017 /std:c++ latest下试了下好像没什么问题 ```cpp // ConsoleApplication1.cpp: 定义控制台应用程序的入口点。 // #include "stdafx.h" #include <cstddef> #include <iostream> #include <cstring> constexpr int N = static_cast<size_t>(3e5 + 5); long long f[3][N][105]; int main() { return 0; std::memset(f, 0, sizeof f); } ``` 以及比赛给的win下mingw 4.8.1 -std=c++11 一样正常运行。 怕是OJ上有什么配置被魔改过了……
by constructor @ 2018-04-11 17:26:09


|