zoukankan      html  css  js  c++  java
  • poj 1463

    dp之,状态转移方程比较好理解。学到的东西就是可以通过拓展状态的维数,是思路更加简便,严谨

    #include <iostream>
    #include <cstdio>
    using namespace std;
    const int maxn=1500+10;
    int head[maxn][15],d[maxn];
    int f[maxn][2];
    int n;
    int min(int a,int b) { return a<b?a:b; } 
    void dp(int x)
    {
    	if(d[x]==0)
    	{
    		f[x][0]=0;
    		f[x][1]=1;
    		return;
    	}
    	for(int i=0;head[x][i]!=-1;i++)
    	{
    		dp(head[x][i]);
    		f[x][1]+=min(f[head[x][i]][0],f[head[x][i]][1]);
    		f[x][0]+=f[head[x][i]][1];
    	}
    	f[x][1]++;
    }
    int main()
    {
    	while(cin>>n)
    	{
    		memset(head,-1,sizeof(head));
    		memset(f,0,sizeof(f));
    		int i;
    		int u,v,m;
    		int s,tot;
    		for(i=0;i<n;i++)
    		{
    			scanf("%d:(%d)",&u,&m);
    			if(i==0) s=u;
    			d[u]=m;
    			tot=0;
    			int j;
    			for(j=0;j<d[u];j++)
    			{
    				scanf("%d",&v);
    				head[u][tot++]=v;
    			}
    		}
    		dp(s);
    		int ans=min(f[s][0],f[s][1]);
    		cout<<ans<<endl;
    	}
    	return 0;
    }
    


  • 相关阅读:
    SGU 194. Reactor Cooling(无源汇有上下界的网络流)
    SGU 197.Nice Patterns Strike Back
    Codeforces 474E
    记一个问题的AC
    UVM Primer
    UVM Primer
    UVM Primer
    UVM Primer
    UVM Primer
    UVM Primer
  • 原文地址:https://www.cnblogs.com/lj030/p/3002214.html
Copyright © 2011-2022 走看看