Valley of Los calculate the number of entry-P1028 explanations dynamic programming problem

Topic links: https://www.luogu.com.cn/problem/P1028

Title Description

We asked to find the number of numbers having the following properties (a natural number input \ (n-\) ):
input a natural number \ (n-(n-\ Le 1000) \) , then the numbers are naturally treated as follows:

  1. Without any treatment;
  2. In its left plus a natural number, but the number of natural numbers can not exceed half of the original;
  3. After adding a few, this rule continues the process until it can not be together until the natural numbers.

Input Format

1 natural numbers \ (n (n \ le 1000 ) \)

Output Format

An integer indicating the number with the number of properties.

problem analysis

We can use dynamic programming to solve this problem.
We make \ (f [i] \) represents a natural number \ (I \) number of values that can be generated is:
\ (F [I] =. 1 + \ sum_ {J =. 1} ^ {n-/ 2} F [J] \)
codes are as follows:

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
int n, f[maxn];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        f[i] = 1;
        for (int j = 1; j <= i/2; j ++)
            f[i] += f[j];
    }
    cout << f[n] << endl;
    return 0;
}

Summary: This is a dynamic programming introductory questions, you can use recursion, recursion do (but do recursive time do not forget to open the memo).

Guess you like

Origin www.cnblogs.com/quanjun/p/11960270.html
Recommended