[hihoCoder] #1096 : Divided Product

时间限制: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,然后居然通过了。有空再想想。

 1 #include <iostream>
 2 #include <vector>
 3 #include <algorithm>
 4 using namespace std;
 5
 6 typedef long long ll;
 7 const ll MOD = 1000000007;
 8
 9 int N, M;
10
11 void dfs(ll &res, ll idx, ll sum, ll pro) {
12     if (sum == N) {
13         if (pro % M == 0) ++res;
14         return;
15     }
16     for (int i = idx + 1; i <= N - sum; ++i) {
17         dfs(res, i, sum + i, pro * i);
18     }
19 }
20
21 void solve() {
22     ll res = 0;
23     dfs(res, 0, 0, 1);
24     cout << res << endl;
25 }
26
27 int main() {
28     while (cin >> N >> M) {
29         solve();
30     }
31 }
时间: 2024-08-05 03:05:50

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

HOJ 1096 Divided Product (DFS)

时间限制: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

[HIHO]DIvide Product

Divided Product 题解 1 #include <iostream> 2 3 using namespace std; 4 // f[0][0][1] = 1; 5 // for (i = 0; i < N; i++) 6 // for (j = 0; j < N; j++) 7 // for (k = 1; k <= M; k++) 8 // if (f[i][j][k] > 0) 9 // for (l = j + 1; l <= N - i; l

微软苏州校招笔试 12月27日

题目1 : Lost in the City 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi gets lost in the city. He does not know where he is. He does not know which direction is north. Fortunately, Little Hi has a map of the city. The map can be considered as a grid

hiho1096_divided_product

题目 给出两个正整数N和M, N <= 100, M <= 50, 可以将N分解成若干个不相等的正整数A1, A2... Ak的和,且A1, A2 ... Ak的乘积为M的倍数.即 N = A1 + A2 + ... + Ak; A1*A2*...Ak % M = 0; 求可以有多少种分解方式? 题目链接: divided product 分析 直接DFS搜索,DFS(cur_sum, cur_max_num, cur_product) 枚举出总和为N的,且各个数字不断增加的方案,然后判断他们

(转载)Cross product

原文地址:https://en.wikipedia.org/wiki/Cross_product Cross product From Wikipedia, the free encyclopedia This article is about the cross product of two vectors in three-dimensional Euclidean space. For other uses, see Cross product (disambiguation). In m

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 following sections. 1 project introduce. The project will be an upgraded version of the existing Yitoa GPTimer. Additional features are required to faci

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

#1392 : War Chess 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 Rainbow loves to play kinds of War Chess games. There are many famous War Chess games such as "Biography of Cao Cao", "Anecdotes of Wagang Mountain", etc. In this problem, let's c

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 - Version 12.1.1 to 12.1.1 [Release 12.1] Oracle Item Master - Version 12.0.6 to 12.0.6 [Release 12] Information in this document applies to any plat

03.product.js

1 /* 2 item.jd.com Compressed by uglify 3 Author:keelii 4 Date: 2014-08-05 6:52:26 [PM] 5 */ 6 function insertScript(t, e) { 7 var i = document.getElementsByTagName("head")[0], 8 s = document.createElement("script"); 9 if (s.setAttribu