結果
問題 | No.196 典型DP (1) |
ユーザー |
![]() |
提出日時 | 2015-04-26 22:09:06 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 903 bytes |
コンパイル時間 | 621 ms |
コンパイル使用メモリ | 46,484 KB |
実行使用メモリ | 17,280 KB |
最終ジャッジ日時 | 2024-07-05 02:52:46 |
合計ジャッジ時間 | 2,017 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:45:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d %d",&n,&k); | ~~~~~^~~~~~~~~~~~~~~ main.cpp:49:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 49 | scanf("%d %d",&a,&b); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <cstdio>#include <cstdlib>#include <algorithm>#include <vector>#include <cstring>#define SIZE 2005#define MOD 1000000007using namespace std;typedef long long int ll;vector <int> vec[SIZE];vector <int> dp[SIZE];int nd[SIZE];void dfs(int v=0,int p=-1){nd[v]=1;dp[v].push_back(1);for(int i=0;i<vec[v].size();i++){int to=vec[v][i];if(to!=p){dfs(to,v);nd[v]+=nd[to];vector <int> nd;nd.resize(dp[v].size()+dp[to].size()-1,0);for(int j=0;j<dp[v].size();j++){for(int k=0;k<dp[to].size();k++){nd[j+k]+=(ll) dp[v][j]*(ll) dp[to][k]%MOD;if(nd[j+k]>=MOD) nd[j+k]-=MOD;}}dp[v]=nd;}}dp[v].push_back(1);}int main(){int n,k;scanf("%d %d",&n,&k);for(int i=0;i<n-1;i++){int a,b;scanf("%d %d",&a,&b);vec[a].push_back(b);vec[b].push_back(a);}dfs();printf("%d\n",dp[0][k]);return 0;}