Poj 1664 _ put the apple, split the integer

Source: Internet
Author: User

ThisIn fact, it is very simple to put M identical apples on the same plate and ask how many ways to put them.

I want to make some changes to this question first. If it is placed on different dishes, the result will be X1 + X2 + X3 +... + Xn = the number of M solutions. A combination of mathematics is called a combination of multiple sets.

If the plate is different and the plate is not empty, this is an ordered split of integers. That is, the result that appears at least once in the combination of multiple sets.

In this question, the plates are the same, that is, the unordered splitting of integers.

The k splitting of n means dividing N into k numbers greater than 0.

The unordered division of integers has a formula: B (n + k, K) = B (n, 1) + B (n, 2) + B (n, 3) ~~~ B (n, k );

Where, the K split of the B (n, k) Table is N.

I'm going to attend classes. paste it.Code:

# Include <iostream> # include <stdio. h> # include <string. h> using namespace STD; int data [30] [30]; int get (int m, int K) {If (data [m] [k]! =-1) return data [m] [k]; If (K = 1 | M = k) return 1; if (M <k) return 0; int sum = 0; For (INT I = 1; I <= K; I ++) {sum + = get (m-K, I );} data [m] [k] = sum; return sum;} int main () {int t; CIN> T; memset (data,-1, sizeof (data )); while (t --) {int M, K; CIN> m> K; int sum = 0; For (INT I = 1; I <= K; I ++) sum + = get (M, I); cout <sum <"\ n";} return 0 ;}

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.