题目链接:UVA - 12186 Another Crisis
#include <bits/stdc++.h>
using namespace std;
int n, t;
vector<int> son[100005];
int dp(int u)
{
if(son[u].empty())return 1;
int k = son[u].size();
vector<int>d;
for(int i = 0; i < k; i++)d.push_back(dp(son[u][i]));
sort(d.begin(), d.end());
int c = (k * t - 1) / 100 + 1;
int ans = 0;
for(int i = 0; i < c; i++)ans += d[i];
return ans;
}
int main()
{
int i, k;
while(cin >> n >> t)
{
memset(son, 0, sizeof(son));
if(n == 0 && t == 0)break;
for(i = 1; i <= n; i++)
{
cin >> k;
son[k].push_back(i);
}
cout << dp(0) << endl;
}
return 0;
}