树形dp题,状态转移方程应该很好推,但一定要细心。
http://poj.org/problem?id=3342
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <string> 5 #include <map> 6 using namespace std; 7 const int maxn = 200 + 10; 8 char buf[maxn]; 9 struct Edge{ 10 int to, next; 11 }edge[maxn << 1]; 12 int head[maxn], N; 13 map<string, int> mapi; 14 int n, k; 15 int dp[maxn][2]; 16 int o[maxn][2]; 17 int get_str(char *dest){ 18 int cnt = 0; 19 char ch; 20 do{ 21 ch = getchar(); 22 }while(ch != EOF && (ch == ' ' || ch == ' ')); 23 if(ch == EOF) return 0; 24 dest[cnt++] = ch; 25 while((ch = getchar()) != ' ' && ch != ' ' && ch != EOF) dest[cnt++] = ch; 26 dest[cnt] = '