树,dfs
感觉自己的理解深了一些,还有个别细节没做到位
记得minlen值要设的足够大,我最开始设置11000就小了,反正越大越好吧
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <cstring>
using namespace std;
int n;
double p,r;
int times = 1;
int minlen = 999999999;
vector<vector<int> > tree;
void dfs(int root, int len){
if(minlen < len) return ;
if(tree[root].size()==0){
if(minlen==len) times++;
else if(minlen > len){
minlen = len;
times = 1;
}
}
for(int i=0; i<tree[root].size(); i++){
dfs(tree[root][i],len+1);
}
}
int main(){
cin >> n >> p >> r;
tree.resize(n);
for(int i=0; i<n; i++){
int k;
cin >> k;
for(int j=0; j<k; j++){
int a;
cin >> a;
tree[i].push_back(a);
}
}
dfs(0,0);
double ans = p * pow((1 + r/100),minlen);
printf("%.4f %d",ans,times);
return 0;
}
唉,长路漫漫