/************************************************* author:running_time* Created time:2015/10/28 Wednesday 20:20:09* Fi Le name:h.cpp ************************************************/#include <cstdio> #include <algorithm># Include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string > #include <vector> #include <queue> #include <deque> #include <stack> #include <list># Include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e3 + 10;const int M = 1e2 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;con St Double EPS = 1e-10;const Double PI = ACOs ( -1.0); int dp[2][n][n];int lcm[n][n];int vec[n];int GCD (int a, int b) { Return b? GCD (b, a% B): A;} void init (void) {for (int i=1; i<=1000; ++i) { for (int j=1; j<=1000; ++j) {Lcm[i][j] = i * J/GCD (i, j); }}}inline void Add (int &x, int y) {x + = y; if (x > MoD) x-= mod;} int main (void) {init (); int n, m, K; while (scanf ("%d%d%d", &n, &m, &k) = = 3) {int t = 0; for (int i=1; i<=m; ++i) {if (m% i = = 0) vec[t++] = i; } int now = 0; for (int i=0, i<=n; ++i) {for (int j=0; j<t; ++j) {dp[now][i][vec[j]] = 0; }} Dp[now][0][1] = 1; for (int. l=1; l<=k; ++l) {now ^= 1; for (int i=0, i<=n; ++i) {for (int j=0; j<t; ++j) {dp[now][i][vec[j]] = 0; }} for (int i=l-1, i<=n; ++i) {for (int j=0; j<t; ++j) { if (dp[now^1][i][vec[j]] = = 0) continue; for (int p=0; p<t; ++p) {int x = i + vec[p]; int y = lcm[vec[j]][vec[p]]; if (x > N | | m% y! = 0) Continue; Dp[now][x][y] = (Dp[now][x][y] + dp[now^1][i][vec[j])% MOD; }}}} printf ("%d\n", Dp[now][n][m]); }//cout << "time Elapsed:" << 1.0 * Clock ()/clocks_per_sec << "s.\n"; return 0;}
DP (optimized) uvalive 6073 Math Magic