Gym - 100952H

Posted starry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gym - 100952H相关的知识,希望对你有一定的参考价值。

H. Special Palindrome

 

A sequence of positive and non-zero integers called palindromic if it can be read the same forward and backward, for example:

15 2 6 4 6 2 15

20 3 1 1 3 20

We have a special kind of palindromic sequences, let‘s call it a special palindrome.

A palindromic sequence is a special palindrome if its values don‘t decrease up to the middle value, and of course they don‘t increase from the middle to the end.

The sequences above is NOT special, while the following sequences are:

1 2 3 3 7 8 7 3 3 2 1

2 10 2

1 4 13 13 4 1

Let‘s define the function F(N), which represents the number of special sequences that the sum of their values is N.

For example F(7) = 5 which are : (7), (1 5 1), (2 3 2), (1 1 3 1 1), (1 1 1 1 1 1 1)

Your job is to write a program that compute the Value F(N) for given N‘s.

Input

The Input consists of a sequence of lines, each line contains a positive none zero integer N less than or equal to 250. The last line contains 0 which indicates the end of the input.

Output

Print one line for each given number N, which it the value F(N).

Examples
input
1
3
7
10
0
output
1
2
5
17

动态规划题目,求数字n可以组成多少个回文串,dp[i][j]表示值为i,以j开头的。
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7 ll dp[500][500];
 8 ll ans[500];
 9 void init(){
10     dp[0][1] = dp[1][1] = dp[2][1] = 1;
11     dp[2][2] = dp[3][1] = dp[3][3] = 1;
12     ans[1] = 1; ans[2] = ans[3] = 2;
13     for(int i = 4; i <= 250; i ++){
14         ll tmp = 0;
15         for(int j = 1; j <= i/2; j ++){
16             if(j==1)dp[i][j] = ans[i-2];
17             else{
18                 ll u = i-j*2;
19                 if(u==0)dp[i][j] = 1;
20                 else{
21                     ll ret = 0;
22                     for(int k = j; k <= u; k ++){
23                         ret += dp[u][k];
24                     }
25                     dp[i][j] = ret;
26                 }
27             }
28             tmp += dp[i][j];
29         }
30         dp[i][i] = 1;
31         tmp += 1;
32         ans[i] = tmp;
33     }
34 }
35 int main(){
36     int n;
37     init();
38     while(scanf("%d",&n)&&n){
39         cout << ans[n] << endl;
40     }
41     return 0;
42 }

 

以上是关于Gym - 100952H的主要内容,如果未能解决你的问题,请参考以下文章

强化学习笔记:Gym入门--从安装到第一个完整的代码示例

openAi-gym 名称错误

解决使用Monitor出现gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables的问题(代码

Gym 100917M Matrix, The

gym第一个程序

gym第一个程序