为什么不能像战略游戏那样只判断该节点选还是不选啊??

P2458 [SDOI2006] 保安站岗

``` #include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #define il inline using namespace std; il int gi() { int x=0,y=1; char ch=getchar(); while(ch<'0'||ch>'9') { if(ch=='-') y=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); } return x*y; } int pre[100045],cnt; struct edge { int next,to; }e[100045]; void add(int from,int to) { e[++cnt].next=pre[from]; e[cnt].to=to; pre[from]=cnt; } int f[1545][2]; void dfs(int x,int y) { f[x][1]=1; int r=pre[x]; while(r!=-1) { if(e[r].to!=y) { dfs(e[r].to,x); f[x][0]+=f[e[r].to][1]; f[x][1]+=min(f[e[r].to][0],f[e[r].to][1]); } r=e[r].next; } } int num[1545]; int main() { freopen("soldier.in","r",stdin); freopen("soldier.out","w",stdout); int n,x; while(cin>>n) { memset(f,0,sizeof(f)); cnt=0; memset(pre,-1,sizeof(pre)); for(int i=0;i<n;i++) { x=gi(); num[x]=gi(); for(int j=1;j<=num[x];j++) { int y=gi(); add(y,x); add(x,y); } } dfs(0,-1); printf("%d\n",min(f[0][0],f[0][1])); } return 0; } ```
by plysc @ 2019-01-19 17:34:25


不要再用一号标题显示头文件的重要性了
by NaCly_Fish @ 2019-01-19 17:44:43


因为战略游戏只考虑两点间(当前节点与其子节点)的关系,而此题要考虑当前节点,其父亲节点,其子节点
by WatT_T @ 2019-01-19 20:34:14


@[2624643550sc](/space/show?uid=38634)
by WatT_T @ 2019-01-19 20:36:16


战略游戏不需要考虑父亲吗
by plysc @ 2019-01-20 13:56:02


%%%%
by plysc @ 2019-01-20 13:56:10


@[2624643550sc](/space/show?uid=38634) 不需要因为x和他的父亲是一条边,x和他的儿子是一条边,是两个阶段(状态??)
by WatT_T @ 2019-01-20 15:22:05


@[WatT_T](/space/show?uid=89398) 不是吧?楼主他没看清题目,题目是有点权的,并不想战略游戏点权均=1
by guodong @ 2019-02-17 21:24:26


战略游戏是守边,而这个是守点。 比如 1->2->3->4 这个数据,战略游戏只守1、4就不行,而本题可以
by Social_Zhao @ 2019-05-05 19:52:13


@[plysc](/space/show?uid=38634)
by Social_Zhao @ 2019-05-05 19:52:32


|