Nyoj 571--Various Division numbers

Source: Internet
Author: User
Tags integer division

Integer division (c) time limit:MS | Memory limit:65535 KB  
Describe

Integer partitioning is a classic problem. Please write a program to complete the following requirements.

Each set of inputs is two integers n and K. (1 <= n <=, 1 <= k <= N)
output
for the input n,k;
The first line: divides n into the number of divisions of a number of positive integers.
Second line: divides n into the sum of k positive integers.
Line three: divides n into the number of divisions that do not exceed the maximum number of K.
Line Fourth: divides n into a number of the sum of the odd positive integers.
Line Fifth: divides n into the sum of a number of different integers.
Line Sixth: Print a blank line
 5 2 
 72333 
prompt
sample output hint: Br>1. Divide 5 into the sum of several positive integers as: 5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1, 1+1+1+1+1
2. Divides 5 into 2 positive integers: 3+2, 4+1
3. Divide 5 into Maximum number Over 2 is divided into: 1+1+1+1+1, 1+1+1+2, 1+2+2
4. Divides 5 into the sum of several odd positive integers into: 5, 1+1+3, 1+1+1+1+1
5. Divides 5 into a number of different integers: 5, 1+4, 2+3

#include <cstdio>#include<iostream>#include<cstring>#include<string>using namespacestd;intdp[ -][ -];intMain () {intN, K, A, B, C, D, E;  while(SCANF ("%d%d", &n, &k)! =EOF) {        //Dividing the positive integer I into the number of positive integers not exceeding J         for(intI=1; i<=n; i++) {             for(intj=1; j<=n; J + +) {                if(j>i) Dp[i][j] =Dp[i][i]; Else if(j = i) dp[i][j] = dp[i][j-1] +1; ElseDP[I][J] = dp[i][j-1] + dp[i-J]            [j]; }        }A =Dp[n][n]; C=Dp[n][k]; //Dividing a positive integer into a number of k positive integers         for(intI=1; i<=n; i++) {             for(intj=1; j<=k; J + +) {                if(j>i) Dp[i][j] =0; Else if(j==i) Dp[i][j] =1; ElseDP[I][J] = dp[i-1][j-1] + dp[i-J]            [j]; }} B=Dp[n][k]; //divide I into odd numbers of no more than J        intOdd = n&1? n:n-1;  for(intI=1; i<=n; i++) {dp[i][1] =1;  for(intj=3; j<=odd; j+=2) {                if(j>i) {if(i&1) Dp[i][j] =Dp[i][i]; ElseDP[I][J] = dp[i][i-1]; }                Else if(j==i) Dp[i][j] = dp[i][i-2] +1; ElseDP[I][J] = dp[i][j-2] + dp[i-J]            [j]; }} D=Dp[n][odd]; //Dividing I into the number of different positive integers         for(intI=1; i<=n; i++) {             for(intj=1; j<=n; J + +) {                if(j>i) Dp[i][j] =Dp[i][i]; Else if(j = i) dp[i][j] = dp[i][i-1] +1; ElseDP[I][J] = dp[i][j-1] + dp[i-j][j-1]; }} e=Dp[n][n]; printf ("%d\n%d\n%d\n%d\n%d\n\n", A, B, C, D, E); Memset (DP,0,sizeof(DP)); }        return 0;}

Nyoj 571--Various Division numbers

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.