题意:
看白书
要点:
白书上写的还是很清楚的,通过递归进行动态规划,vector还真是好用,暑假的时候学一下。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<vector>
#define maxn 100005
using namespace std;
int n, T;
vector<int> son[maxn];int dp(int x)
{if (son[x].empty())return 1;int k = son[x].size();vector<int> d;for (int i = 0; i < k; i++)d.push_back(dp(son[x][i]));//d表示x的子结点需要的工人签字数sort(d.begin(), d.end());int ans = 0;int c = (k*T-1)/100 + 1; //消除浮点误差for (int i = 0; i < c; i++)//每次找它的前c个ans += d[i];return ans;
}int main()
{int x;while (scanf("%d%d",&n,&T)==2){if (n == 0 && T == 0)break;for (int i = 0; i <= maxn; i++)//每次都要清空vector数组son[i].clear();for (int i = 1; i <= n; i++){scanf("%d", &x);son[x].push_back(i);//son[i]为结点i的子节点列表}printf("%d\n", dp(0));}return 0;
}