# Hdu1028: integer splitting

Source: Internet
Author: User

Returns the split score of an integer ..

One solution is the primary function.

`# Include <iostream> # include <stdio. h> # include <string. h> # include <algorithm> # include <string> # include <ctype. h> using namespace std; # define MAXN extends int dp [2] [130]; int main () {int n; while (scanf ("% d", & n )! = EOF) {memset (dp, 0, sizeof (dp); dp [0] [0] = 1; for (int I = 1; I <= n; I ++) {for (int j = 0; j <= n; j ++) {for (int k = 0; j + k * I <= n; k ++) {dp [I % 2] [j + k * I] + = dp [(i-1) % 2] [j];} dp [(i-1) % 2] [j] = 0 ;}} printf ("% d \ n", dp [n % 2] [n]);} return 0 ;}`
View Code

There is also a dp method

Dp [n] [m] indicates the number of solutions to split n into numbers not greater than m.

During the transfer, the data is classified by the maximum number in the split ..

Dp [n] [m] = sum {I = 1 ~ N} (dp [I] [n-I]) ---- the maximum number of classes is 1 ~ N

The code is written as recursive memory-based search.

`# Include <stdio. h> # include <string. h> # include <algorithm> # include <string> # include <ctype. h> using namespace std; # define MAXN short int dp [130] [130]; int dfs (int n, int m) {if (dp [n] [m]! =-1) return dp [n] [m]; if (m = 0) return dp [n] [0] = 0; if (n = 0) return dp [0] [m] = 1; if (m> n) return dfs (n, n); return dp [n] [m] = dfs (n M-1) + dfs (n-m, m);} int main () {memset (dp,-1, sizeof (dp); int t, x; while (scanf ("% d", & x )! = EOF) {printf ("% d \ n", dfs (x, x);} return 0 ;}`
View Code

Hdu1028: integer splitting

Related Keywords:

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.