版本比较
题解 CF762F [Tree nesting]
正文
增加 10 行删除 10 行
23 行未改动24252627282829303132323334353618 行未改动555657585959606162626364656613 行未改动808182838484858687886 行未改动9596979899991001011011021031041051051061071081081091101111121131141141151161171187 行未改动23 行未改动
```#include <bits/stdc++.h>using namespace std;
const int mod = 1e9 + 7 , N = 1000 , M = 12;inline void add(int &x , int y) {x += y ; if(x >= mod) x -= mod;}inline void sub(int &x , int y) {x -= y ; if(x < 0) x += mod;}
struct Tree : vector<vector<int>> { void AddEdge(int x , int y) { this->at(x).push_back(y) , this->at(y).push_back(x); }18 行未改动 } } return x;}
int Log2[1 << M];struct TreeMatcher {
vector<int> dp[N][M];int dfs(Tree &S , Tree &T , int s , int t) { vector<int> &cur = dp[s][t]; if(!cur.empty()) return cur.back();13 行未改动 if(S.size() < T.size()) return 0; if(T.size() <= 1) return S.size();
auto clr = [&] { for(int i = 0 ; i < S.size() ; ++i) for(int j = 0 ; j < T.size() ; ++j) dp[i][j].clear(); };6 行未改动 add(ans , dfs(s , t , i , j)); } return ans;}
};
inline int Inv(int x) { return x <= 1 ? x : 1LL * (mod - mod / x) * Inv(mod % x) % mod;}
Tree S , T;TreeMatcher matcher;
int main() { auto Input = [&](Tree &tree) { int n ; scanf("%d" , &n); tree.resize(n);
for(int i = 1 , x , y ; i < n ; ++i) { scanf("%d %d" , &x , &y); tree.AddEdge(x - 1, y - 1); }7 行未改动