时间限制: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. jacoco统计自动化测试代码覆盖率

    一.下载jacoco, ant工具 jacoco: http://www.eclemma.org/jacoco/: ant: http://ant.apache.org 并添加到环境变量: 二.不停j ...

  2. WIN7使用技巧 让电脑变身WiFi热点,让手机、笔记本共享上网,如何开启无线网络,共享无线网络

    将win7电脑变身WIFI热点,让手机.笔记本共享上网 用win7建立无线局域网,可以共享上网可以局域网游戏. 开启windows 7的隐藏功能:虚拟WIFI和SoftAP(即虚拟无线AP),就可以让 ...

  3. Oracle 与 SqlServer 的区别浅析总结

    我主要用过的数据库为Oracle10g和SqlServer2008,通过实际运用和查阅资料整理如下: 主题 Oracle 10g SQLServer 2008 存储过程格式 Create Or Rep ...

  4. c语言中static、extern、void的重载

    static:   1.在函数内部,表示该变量的值在各个调用间一直保持延续性:     2.在函数这一级,表示该函数只对本文件可见. extern: 1.用于函数定义,表示全局可见(属于冗余的):   ...

  5. 教您使用java爬虫gecco抓取JD全部商品信息

    gecco爬虫 如果对gecco还没有了解可以参看一下gecco的github首页.gecco爬虫十分的简单易用,JD全部商品信息的抓取9个类就能搞定. JD网站的分析 要抓取JD网站的全部商品信息, ...

  6. spring的applicationContext.xml中的DBCP配置如下:

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy ...

  7. 〖Linux〗以后台方式启动/结束指定程序/命令(不受 exit 或点击窗口关闭按钮等终端退出操作的影响)

    #!/bin/bash - #=============================================================================== # # F ...

  8. Android进程注入

    全部代码在这里下载:http://download.csdn.net/detail/a345017062/8133239 里面有两个exe.inj是一个C层进程注入的样例.inj_dalvik是我写的 ...

  9. poj 2226 二分图 最小点覆盖 , 最大流

    题目就是问怎样用最小的板覆盖全部的草地.能够横着放.也能够竖着放,同意一个草地放多个点. 建图方法就是 每一个横向的草地作为X,纵向连续的草地作为Y.     X连接Y的边表示,  这里有他们的公共点 ...

  10. JS禁止后退键(backspace)使浏览器后退

    背景说明: 今天项目测试中,同事发现一个Bug,当键盘敲下后退键(Backspace)后,浏览器自动后退,不符合需求,故建议禁止浏览器后退键. 提出需求: 当键盘敲下后退键(Backspace)后 1 ...