結果
問題 | No.196 典型DP (1) |
ユーザー |
![]() |
提出日時 | 2018-12-26 11:07:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 1,541 bytes |
コンパイル時間 | 979 ms |
コンパイル使用メモリ | 92,904 KB |
実行使用メモリ | 35,200 KB |
最終ジャッジ日時 | 2024-10-01 14:42:23 |
合計ジャッジ時間 | 2,764 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
#include <iostream> #include <stdio.h> #include <fstream> #include <algorithm> #include <string> #include <map> #include <set> #include <queue> #include <stack> #include <vector> #include <limits.h> #include <math.h> #include <functional> #include <bitset> #include <iomanip> #include <cassert> #define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i)) #define debug(x) cerr << #x << ": " << x << '\n' #define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n' #define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n' using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int,int> Pii; typedef vector<int> vint; typedef vector<ll> vll; const ll INF = INT_MAX; const ll MOD = 1e9+7; int N,K; vector<vint> G; ll dp[2010][2010]; ll tmp[2010]; ll size[2010]; void dfs(int v,int par){ size[v]=1; dp[v][0]=1; for(int chi:G[v])if(chi!=par){ dfs(chi,v); fill(tmp,tmp+K+1,0); for(int k=size[v];k>=0;k--){ repeat(l,size[chi]+1){ tmp[k+l] = (tmp[k+l]+dp[v][k]*dp[chi][l]%MOD)%MOD; } } size[v]+=size[chi]; swap(tmp,dp[v]); } if(size[v]<=K){ dp[v][size[v]]=1; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); cin>>N>>K; G.resize(N); repeat(i,N-1){ int a,b;cin>>a>>b; G[a].push_back(b); G[b].push_back(a); } dfs(0,-1); //debug(dp[3][1]); cout << dp[0][K] << endl; return 0; }