时间限制:10000ms
单点时限:1000ms
内存限制:256MB

描述

Given two positive integers N and M, please divide N into several integers A1, A2, ..., Ak (k >= 1), so that:

1. 0 < A1 < A2 < ... < Ak;

2. A1 + A2 + ... + Ak = N;

3. A1, A2, ..., Ak are different with each other;

4. The product of them P = A1 * A2 * ... * Ak is a multiple of M;

How many different ways can you achieve this goal?

输入

Two integers N and M. 1 <= N <= 100, 1 <= M <= 50.

输出

Output one integer -- the number of different ways to achieve this goal, module 1,000,000,007.

样例提示

There are 4 different ways to achieve this goal for the sample:

A1=1, A2=2, A3=4;

A1=1, A2=6;

A1=2, A2=5;

A1=3, A2=4.

样例输入
7 2
样例输出
4

说好的这题是动规呢?想了半天动规没想出来,写了个DFS,然后居然通过了。有空再想想。

 #include <iostream>
#include <vector>
#include <algorithm>
using namespace std; typedef long long ll;
const ll MOD = ; int N, M; void dfs(ll &res, ll idx, ll sum, ll pro) {
if (sum == N) {
if (pro % M == ) ++res;
return;
}
for (int i = idx + ; i <= N - sum; ++i) {
dfs(res, i, sum + i, pro * i);
}
} void solve() {
ll res = ;
dfs(res, , , );
cout << res << endl;
} int main() {
while (cin >> N >> M) {
solve();
}
}

[hihoCoder] #1096 : Divided Product的更多相关文章

  1. HOJ 1096 Divided Product (DFS)

    时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Given two positive integers N and M, please divide N into sev ...

  2. hiho1096_divided_product

    题目 给出两个正整数N和M, N <= 100, M <= 50, 可以将N分解成若干个不相等的正整数A1, A2... Ak的和,且A1, A2 ... Ak的乘积为M的倍数.即 N = ...

  3. 【堆栈应用一】一个数divided=几个最小质因数的乘积

    /******************************************堆栈:一个数divided几个质因数(质因数的乘积为N)***************************** ...

  4. hihoCoder 1392 War Chess 【模拟】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2016)网络赛)

    #1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess gam ...

  5. Optimizing Item Import Performance in Oracle Product Hub/Inventory

    APPLIES TO: Oracle Product Hub - Version 12.1.1 to 12.1.1 [Release 12.1] Oracle Inventory Management ...

  6. timer Compliant Controller project (1)--Product introduction meeting

    Last week ,I lead the meeting for new project. i'm  very excited. The meeting is divided into the fo ...

  7. PAT甲级——1096 Consecutive Factors (数学题)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/91349859 1096 Consecutive Factors  ...

  8. hihoCoder #1072 辅导

    题意 $\DeclareMathOperator{\lcm}{lcm}$选 $k$ ($k\le 10$) 个 $1$ 到 $n$($n\le 10^9$)之间的整数(可以相同),使得 $\lcm(a ...

  9. hihoCoder 1584 Bounce 【数学规律】 (ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)

    #1584 : Bounce 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 For Argo, it is very interesting watching a cir ...

随机推荐

  1. JSP的范围-作用域(web基础学习笔记五)

    JSP的范围(作用域) 在JSP页面中的对象,包括用户创建的对象如JavaBean,都有一个范围属性,这个范围也被叫做“作用域”.范围定义了在什么时间内,在哪一个JSP页面中可以访问这些对象.例如,s ...

  2. redis 安装 命令

    安装: http://redis.io/download 在线操作命令:http://try.redis.io/ 命令查询:https://redis.readthedocs.org/en/lates ...

  3. html中title属性换行实现

    本文主要讲解titile属性换行的实现方式.<title> 元素可定义文档的标题,可以应用在img.a等标签上. 1.实现方式: <!DOCTYPE html> <htm ...

  4. iOS 事件传递及响应过程

    iOS 事件传递及响应过程 -->>事件到来-->>事件分发 -->>事件响应 事件( Events) 官方文档( Events(iOS)) 是这样描写叙述的: U ...

  5. 深入理解 Linux 内存管理

    1. 内存地址 以Intel的中央处理器为例,Linux 32位的系统中.物理内存的基本单位是字节(Byte),1个字节有8个二进制位. 每一个内存地址指向一个字节,内存地址加1后得到下一个字节的地址 ...

  6. MySQL必知必会笔记(六)存储过程 游标 触发器

    留印:http://blog.sina.com.cn/s/articlelist_1254871964_5_1.html   第二十三章 使用存储过程     MySQL5 中添加了存储过程的支持. ...

  7. java常见错误--Access restriction: The type BASE64Encoder

    Access restriction: The type BASE64Encoder is not accessible due to restrict 在Eclipse中编写Java代码时,用到了B ...

  8. JavaScript 设计模式之建造者模式

    一.建造者模式概念解读 1.建造者模式概念文字解读 建造者模式可以将一个复杂对象的构建与其表示分离,使得同样的构建过程可以创建不同的表示.也就是说如果我们用了建造者模式,那么用户就需要指定需要建造的类 ...

  9. Java Socket 编程之Socket与ServerSocket的区别

    http://www.cnblogs.com/hq-antoine/archive/2012/02/11/2346474.html 1.1 ServerSocket类    创建一个ServerSoc ...

  10. python练习笔记——用列表推导式生成二维列表

    用列表推导式如何生成如下列表:[[1, 2, 3], [4, 5, 6], [7, 8, 9]] inner_list = [] outer_list = [] for i in range(1,10 ...