Nyoj 651--n divided into the number of 2 or more different positive integers

Source: Internet
Author: User

Cut The rope time limit:MS | Memory limit:65535 KB
Describe

We have a rope whose length is L. We'll cut the rope into and to the other parts, the length of each of the must is an integer, and no, and the same Le Ngth.
Your task is to calculate there exists how many results after the cutting. We say results is different if and only if there was at the least one part, which we can find in one result but can not fi nd in the other result

Input
There is a integer t (1 <= T <= 50000) in the first line, which indicates there was t test cases in total.
For each test case, there is only one of the integer L (1 <= L <= 50000) which has the same meaning as above.
Output
For each test case, you should output the correct answer of the above task in one line.
Because the answer is very large, you should just output the remainder of it divided by 1000000 instead
Sample input
3236
Sample output
013

This problem has a high limit on time and space, so we should try our best to optimize it.

in general, N is divided into The number of different positive integers, this problem can be solved by DP, the definition of dp[i][j] for I is divided into less than the number of J. However, here will encounter a very difficult problem: 1≤n≤50000, so if the definition of this state, space, time complexity to reach 25*108, time, space will exceed the limit!

Therefore, the general approach does not work. Another idea: The title is also in the division of N 2, 3 、... The sum of the number of different positive integers.

In order to divide the number of n into K-positive integers, this problem can also be solved by DP: defining DP[I][J] is divided into the number of J different positive integers.

The range of I is still [1, 50000], so what about J? That is, I can be divided into the maximum number of copies?

Assuming that we divide I into J, then in the case of I taking the minimum, i=1+2+...+j (each element of the division is not the same) = (1+J) *j/2. because of the i≤50000, so J to take up to 316, and not be able to divide more, and then will appear the same. Therefore, j≤316

Time, space size reduced to 316*50000=1.58*107, because the coefficient is small, can be AC

#include <cstdio>#include<iostream>#include<cstring>#include<string>using namespacestd;Const intMAXN =50005;Const intMOD =1000000;intdp[maxn][317];voidinit () {dp[1][1] =1;  for(intI=2; i< the; i++) dp[1][i] =0;  for(intI=2; i<maxn; i++) {         for(intj=1; j<317; J + +) {            if(j>=i) Dp[i][j] =0; ElseDP[I][J] = (dp[i-j][j-1] + dp[i-j][j])%MOD;        }    }} intMain () {init (); intT, n, ans; scanf ("%d", &T);  while(t--) {scanf ("%d", &N); Ans=0;  for(intI=2; i<317; i++) ans = (ans + dp[n][i])%MOD; printf ("%d\n", ans); }    return 0;}

Nyoj 651--n divided into the number of 2 or more different positive integers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.