結果
問題 | No.196 典型DP (1) |
ユーザー | Mi |
提出日時 | 2021-12-08 20:27:06 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 496 ms / 2,000 ms |
コード長 | 3,565 bytes |
コンパイル時間 | 4,334 ms |
コンパイル使用メモリ | 241,468 KB |
実行使用メモリ | 222,848 KB |
最終ジャッジ日時 | 2024-07-16 08:42:13 |
合計ジャッジ時間 | 15,033 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 1 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 1 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,944 KB |
testcase_13 | AC | 3 ms
6,944 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 13 ms
10,368 KB |
testcase_16 | AC | 41 ms
30,464 KB |
testcase_17 | AC | 101 ms
66,176 KB |
testcase_18 | AC | 184 ms
119,424 KB |
testcase_19 | AC | 245 ms
151,680 KB |
testcase_20 | AC | 353 ms
222,336 KB |
testcase_21 | AC | 349 ms
222,464 KB |
testcase_22 | AC | 350 ms
222,336 KB |
testcase_23 | AC | 413 ms
222,464 KB |
testcase_24 | AC | 403 ms
222,592 KB |
testcase_25 | AC | 398 ms
222,464 KB |
testcase_26 | AC | 487 ms
222,720 KB |
testcase_27 | AC | 488 ms
222,848 KB |
testcase_28 | AC | 485 ms
222,848 KB |
testcase_29 | AC | 492 ms
222,756 KB |
testcase_30 | AC | 496 ms
222,720 KB |
testcase_31 | AC | 466 ms
222,464 KB |
testcase_32 | AC | 473 ms
222,464 KB |
testcase_33 | AC | 466 ms
222,464 KB |
testcase_34 | AC | 468 ms
222,592 KB |
testcase_35 | AC | 472 ms
222,592 KB |
testcase_36 | AC | 469 ms
222,464 KB |
testcase_37 | AC | 370 ms
222,464 KB |
testcase_38 | AC | 482 ms
222,464 KB |
testcase_39 | AC | 466 ms
222,336 KB |
testcase_40 | AC | 489 ms
222,464 KB |
testcase_41 | AC | 2 ms
6,944 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,940 KB |
ソースコード
#include<bits/stdc++.h> #include<atcoder/all> using namespace std; using namespace atcoder; typedef long long ll; typedef long double ld; typedef pair<ll,ll> P; typedef pair<int,int> Pi; #define rep(i,n) for(ll i=0;i<n;i++) #define FOR(i,a,b) for(ll i=a;i<b;i++) #define rrep(i,n) for(ll i=n-1;i>=0;i--) #define rFOR(i,a,b) for(ll i=a-1;i>=b;i--) #define all(x) (x).begin(),(x).end() #define fi first #define se second #define endl "\n" istream &operator>>(istream &is, modint &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint &a) { return os << a.val(); } istream &operator>>(istream &is, modint998244353 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint998244353 &a) { return os << a.val(); } istream &operator>>(istream &is, modint1000000007 &a) { long long v; is >> v; a = v; return is; } ostream &operator<<(ostream &os, const modint1000000007 &a) { return os << a.val(); } template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;} template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;} template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";} template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";} template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;} template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;} template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;} template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;} template<class T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); } template<class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); } const ll mod=1'000'000'007; const ll inf=1'000'000'000'000'000'00; const int INF=1'000'000'000; const double EPS=1e-10; const double PI=acos(-1); using mint=modint1000000007; int main(){ cin.tie(0);ios::sync_with_stdio(false); int n,k; cin>>n>>k; vector<vector<int>> g(n); rep(i,n-1){ int a,b; cin>>a>>b; g[a].push_back(b); g[b].push_back(a); } auto dp=make_vec(n,n+1,2,mint(0)); auto sz=make_vec(n,0); auto dfs=[&](auto &&dfs,int v,int pre)->void{ sz[v]=1; dp[v][1][1]=1; dp[v][0][0]=1; for(auto &&to:g[v]){ if(to==pre) continue; dfs(dfs,to,v); int x=sz[v],y=sz[to]; auto ndp=make_vec(x+y+1,2,mint(0)); rep(i,x+1)rep(j,y+1){ ndp[i+j][0]+=dp[v][i][0]*dp[to][j][0]; ndp[i+j][0]+=dp[v][i][0]*dp[to][j][1]; ndp[i+j][1]+=dp[v][i][1]*dp[to][j][1]; } sz[v]+=sz[to]; dp[v]=ndp; } }; dfs(dfs,0,-1); cout<<dp[0][k][0]+dp[0][k][1]<<endl; }