本文共 1561 字,大约阅读时间需要 5 分钟。
1、
2、题目大意:
有n个字符串,每个字符串都有一个价值,如果第i个字符串是第j个字符串的前缀,那么第i个字符串就是第j个字符串的父亲,这样就会组成一棵树,子节点的价值都更新到父节点的价值上,然后按顺序输出即可
3、题目:
One day my teacher gave me a problem to solve. I was given N unique names andeach name has a value. Name is a string consisting of lowercase Latin letters withlength less than 10. Value is a positive integer less than 100. Initially these namesare sorted in lexicographic order. Now if the j-th name is the prefix of the i-th nameand has the max length, j is thefather of i. Then numbers 1 to N form a tree. Fromleafto root, each son's value should be added to father's value. After I added thesevalues, my teacher ask me to show allthese values.
Can you help me with the problem?
23a ab ac5 10 155a ab abb ac b5 10 100 15 6
30 10 15130 110 100 15 6
Huge input, scanf is recommended.
zzxchavo @HEU
4、Ac代码:
#include#include #include using namespace std;#define N 100005char s[N][12];int w[N];int check(int a,int b){ int len=strlen(s[a]); for(int i=0;i
转载地址:http://igddi.baihongyu.com/