#include <iostream> #include <cstring> #include <vector> #include <algorithm> using namespace std; const int N=1e5+3; int f[N],n,K; vector<int> g[N]; void dfs(int x){ int b[N],tot; tot=0; if(g[x].size()==0){ f[x]=1; return; } for(auto y:g[x]){ dfs(y); b[++tot]=f[y]; } sort(b+1,b+1+tot); int t=int(g[x].size()/100.0*K*1.0); if(double(t)!=(double)(g[x].size()/100.0*K*1.0)) t++; for(int i=1;i<=t;++i) f[x]+=b[i]; } signed main(){ while(cin>>n>>K,n||K){ for(int i=1;i<=n;i++){ int x; cin>>x; g[x].push_back(i); } dfs(0); cout << f[0]<<endl; for(int i=0;i<=n;i++) f[i]=0,g[i].clear(); } }
标签:1.0,int,tot,dfs,Another,UVA,include,Crisis,size From: https://www.cnblogs.com/towboa/p/17318423.html