/************************************************
* Author :Running_Time
* Created Time :2015/10/28 星期三 20:20:09
* File 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 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int M = 1e2 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const 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(优化) UVALive 6073 Math Magic的更多相关文章

  1. UVALive 6073 Math Magic

                                                  6073 Math MagicYesterday, my teacher taught us about m ...

  2. Math Magic(完全背包)

    Math Magic Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Sta ...

  3. hdu3585 二分最大团(dp优化)

    题意       给你一些点( <= 50),让你找到k个点,使得他们之间的最小距离最大. 思路:       求最小的最大,我们可以直接二分去枚举距离,但是要注意,不要去二分double找距离 ...

  4. 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree

    // 树形DP CCPC网络赛 HDU5834 Magic boy Bi Luo with his excited tree // 题意:n个点的树,每个节点有权值为正,只能用一次,每条边有负权,可以 ...

  5. NOIP2015 子串 (DP+优化)

    子串 (substring.cpp/c/pas) [问题描述] 有两个仅包含小写英文字母的字符串 A 和 B.现在要从字符串 A 中取出 k 个 互不重 叠 的非空子串,然后把这 k 个子串按照其在字 ...

  6. LCIS tyvj1071 DP优化

    思路: f[i][j]表示n1串第i个与n2串第j个且以j结尾的LCIS长度. 很好想的一个DP. 然后难点是优化.这道题也算是用到了DP优化的一个经典类型吧. 可以这样说,这类DP优化的起因是发现重 ...

  7. 取数字(dp优化)

    取数字(dp优化) 给定n个整数\(a_i\),你需要从中选取若干个数,使得它们的和是m的倍数.问有多少种方案.有多个询问,每次询问一个的m对应的答案. \(1\le n\le 200000,1\le ...

  8. dp优化1——sgq(单调队列)

    该文是对dp的提高(并非是dp入门,dp入门者请先参考其他文章) 有时候dp的复杂度也有点大...会被卡. 这几次blog大多数会讲dp优化. 回归noip2017PJT4.(题目可以自己去百度).就 ...

  9. loj6171/bzoj4899 记忆的轮廊(期望dp+优化)

    题目: https://loj.ac/problem/6171 分析: 设dp[i][j]表示从第i个点出发(正确节点),还可以有j个存档点(在i点使用一个存档机会),走到终点n的期望步数 那么 a[ ...

随机推荐

  1. Goldbach's Conjecture

     Goldbach's Conjecture Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

  2. LUA之string的使用

    --string.len(s)          --返回字符串s的长度 --string.rep(s, n)--返回重复n次字符串s的串,你使用string.rep("a", 2 ...

  3. 关于seajs

    (这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) 最近经常听到各种JS前缀的名称,瞬间感觉自己弱爆了,啥都没用过呢,这么下去将来怎么嫁人呢.   ...

  4. Android 云服务器的搭建和友盟APP自动更新功能的实现

    setContentView(R.layout.activity_splash); //Bmob SDK初始化--只需要这一段代码即可完成初始化 //请到Bmob官网(http://www.bmob. ...

  5. snoopy 强大的PHP采集类使用实例代码

    下载地址: http://www.jb51.net/codes/33397.html Snoopy的一些特点: 1抓取网页的内容 fetch 2 抓取网页的文本内容 (去除HTML标签) fetcht ...

  6. Firefox上Web开发工具库一览

    Firefox的目标之一就是尽可能地使web开发者的生活更简单高效,并通过提供工具和具有很强扩展性的浏览器使人们创造出神奇的东西.使web开发者使用Firefox的时候,浏览器可以提供大量开发工具和选 ...

  7. cas单点注销失败Error Sending message to url endpoint

    最近在做cas单点登录时,由于是单点登录.必然会涉及到单点注销,然而在做单点注销时由于对cas注销机制不了解加之测试条件所致,所有测试都是在本机下完成(机器性能较低,没用虚拟机):导致折腾了很久.网上 ...

  8. Win7下虚拟机个人使用小结:Virtual PC,VMware和VirtualBox

    想来用了很多年的虚拟机了,换了Win7之后,种种原因又需要使用虚拟机,这里就简单介绍和比较一下. 点击小图看大图. Virtual PC: 如果想做Windows虚拟机的话,Virtual PC在之前 ...

  9. 【JAVA、C++】LeetCode 016 3Sum Closest

    Given an array S of n integers, find three integers in S such that the sum is closest to a given num ...

  10. iOS图形处理和性能(转)

    在之前的文章里,我们探讨了基于多种不同技术来实现自定义的UIButton,当然不同的技术所涉及到的代码复杂度和难度也不一样.但是我也有意提到了基于不同方法的实现所体现出的性能表现也不一一相同.   [ ...