Title Link: Http://codeforces.com/problemset/problem/431/C
Test instructions: To a k-tree, each node has a K son, and then Benquan from left to right 1-k, given N, K, D, ask at least one edge weight >=d and then the sum is n how many ways
Solution: Dp[i][j][0] represents the current to layer I, and for J, no more than the number of Benquan of D, Dp[i][j][1] represents the current to layer I, and for J, there are more than the number of Benquan of D.
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <vector>#include <set>#include <queue>#include <map>#include <cmath>Using NamespaceStd;typedef Long LongLL;Const IntMoD= 1e9+7;LL DP[101][101][2];IntMain(){ IntN,K,D;Cin>>N>>K>>D;Dp[0][0][0] = 1; For(IntI= 0;I<N;I++) For(IntJ= 0;J<N;J++) { For(IntX= 1;X<D&&X+J<=N;X++)Dp[I+1][J+X][0] = (Dp[I+1][J+X][0]+Dp[I][J][0])%MoD; For(IntX= 1;X<=K&&X+J<=N;X++) If(X<D)Dp[I+1][J+X][1] = (Dp[I+1][J+X][1]+Dp[I][J][1])%MoD; ElseDp[I+1][J+X][1] = (Dp[I+1][J+X][1]+Dp[I][J][1]+Dp[I][J][0])%MoD; } IntAns= 0; For(int I = 1 I <= N; I ++) ans = (ans +dp[i][ n][1])%mod cout << ans << Endl; /span>
Codeforces Round #247 (Div. 2) C. K-tree