結果
| 問題 |
No.196 典型DP (1)
|
| コンテスト | |
| ユーザー |
chocopuu
|
| 提出日時 | 2019-05-06 21:27:00 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 13 ms / 2,000 ms |
| コード長 | 1,915 bytes |
| コンパイル時間 | 1,724 ms |
| コンパイル使用メモリ | 173,336 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-28 11:18:53 |
| 合計ジャッジ時間 | 3,407 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
string get_str(string s) {
s+=',';
string ret="";
for(int i=0; i<s.size(); i++) {
if(s[i]==',') ret+="=%ld, ";
else ret+=s[i];
}
return ret;
}
#define dump(...) printf(get_str(#__VA_ARGS__).c_str(),__VA_ARGS__);cout<<endl
#define endl '\n'
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0)
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
for(auto &e:t) fill_v(e,v);
}
int N,K;
vint g[2002];
vector<int>dfs(int now,int par){
vector<int>dp(1,1);
for(auto e:g[now]){
if(e==par)continue;
vector<int>tmp = dfs(e,now);
vector<int>new_dp(dp.size()+tmp.size()-1);
rep(i,0,dp.size()){
rep(j,0,tmp.size()){
(new_dp[i+j]+=dp[i]*tmp[j])%=MOD;
}
}
dp=new_dp;
}
dp.push_back(1);
return dp;
}
signed main()
{
IOS();
cin>>N>>K;
rep(i,0,N-1){
int a,b;
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
cout<<dfs(0,-1)[K]<<endl;
}
chocopuu