整数划分问题--DFS
2017-08-12 20:07
344 查看
单点时限: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.
例子输入
7 2
例子输出
4
例子提示
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.
思路就是暴力 , 把全部情况都试一下.
内存限制: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.
例子输入
7 2
例子输出
4
例子提示
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.
思路就是暴力 , 把全部情况都试一下.
#include <iostream> using namespace std; typedef unsigned long long ull; ull N, M; ull r = 0; const ull MOD = 1000000007; void dfs (ull i, ull s, ull p) { if (s == N) { if (p % M == 0) r++; return; } for (ull j = i + 1; j < N - s + 1; j++) { dfs (j, s + j, p * j); } } int main () { cin >> N >> M; dfs (0, 0, 1); cout << r % MOD << endl; return 0; }
相关文章推荐
- 整数划分问题--DFS
- 整数划分问题 【俩方法:1.dp 2.dfs枚举】
- OpenJudge简单的整数划分问题两种方法(DFS)(动态规划0ms),全局题号7215,已AC
- 整数划分问题(续)
- 将整数n分成k份,且每份不能为空,任意两种分法不能相同(不考虑顺序)【划分问题】
- 整数划分问题
- C语言实现整数划分问题
- 整数划分问题
- 整数划分问题
- 整数划分问题
- 整数划分问题解析
- 递归 放苹果问题和整数划分问题
- 复杂的整数划分问题
- 整数划分 --- 一个老生长谈的问题 动态规划
- 整数划分问题
- 整数划分 --- 一个老生长谈的问题
- 0002算法笔记——【递归】排列问题,整数划分问题,Hanoi问题
- OJ演练--整数划分(经典DP问题)
- 讨论一类整数划分问题
- 区间dp 整数划分问题