結果
問題 | No.196 典型DP (1) |
ユーザー | pione |
提出日時 | 2020-07-30 21:27:13 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 2,395 bytes |
コンパイル時間 | 1,653 ms |
コンパイル使用メモリ | 172,048 KB |
実行使用メモリ | 26,624 KB |
最終ジャッジ日時 | 2024-07-04 20:21:52 |
合計ジャッジ時間 | 3,616 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 1 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 1 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 2 ms
5,376 KB |
testcase_13 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 3 ms
5,376 KB |
testcase_16 | AC | 5 ms
6,400 KB |
testcase_17 | AC | 8 ms
8,064 KB |
testcase_18 | AC | 10 ms
9,728 KB |
testcase_19 | AC | 12 ms
10,368 KB |
testcase_20 | AC | 14 ms
11,648 KB |
testcase_21 | AC | 15 ms
11,776 KB |
testcase_22 | AC | 14 ms
11,904 KB |
testcase_23 | AC | 18 ms
17,536 KB |
testcase_24 | AC | 16 ms
15,616 KB |
testcase_25 | AC | 16 ms
15,104 KB |
testcase_26 | AC | 19 ms
26,624 KB |
testcase_27 | AC | 18 ms
26,496 KB |
testcase_28 | AC | 18 ms
26,624 KB |
testcase_29 | AC | 18 ms
26,624 KB |
testcase_30 | AC | 18 ms
26,496 KB |
testcase_31 | AC | 22 ms
11,776 KB |
testcase_32 | AC | 22 ms
11,776 KB |
testcase_33 | AC | 22 ms
11,776 KB |
testcase_34 | AC | 21 ms
11,776 KB |
testcase_35 | AC | 21 ms
11,776 KB |
testcase_36 | AC | 20 ms
11,776 KB |
testcase_37 | AC | 14 ms
11,776 KB |
testcase_38 | AC | 20 ms
11,776 KB |
testcase_39 | AC | 19 ms
11,904 KB |
testcase_40 | AC | 21 ms
11,776 KB |
testcase_41 | AC | 1 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 2 ms
5,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout<<d<<endl; #define coutd(d) cout<<std::setprecision(10)<<d<<endl; #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using vtp = vector<tuple<ll,ll,ll>>; using vb = vector<bool>; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9+10; const ll MOD = 1e9+7; const ll LINF = 1e18; const ll maxn_eratosthenes = 100005; bool _is_prime[maxn_eratosthenes]; vector<ll> P; ll dp[2005][2005]; // vまでで、i個を塗る通り数 ll n,k; vll G[2005]; ll num[2005]; void dfs(ll v, ll p){ vll child; for(auto &nv: G[v]){ if(nv==p) continue; dfs(nv,v); child.push_back(nv); } dp[v][0]=1; for(auto nv: child){ vll sub(num[v]+num[nv]+1); for(ll i=0; i<=num[v]; i++){ for(ll j=0; j<=num[nv]; j++){ (sub[i+j]+=dp[v][i]*dp[nv][j]%MOD)%=MOD; } } num[v]+=num[nv]; for(ll i=0; i<=num[v]; i++) dp[v][i]=sub[i]; } num[v]++; dp[v][num[v]]=1; } signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); cin>>n>>k; rep(i,n-1){ ll a,b; cin>>a>>b; G[a].push_back(b); G[b].push_back(a); } dfs(0,-1); cout<<dp[0][k]<<endl; }