Gym - 100952H Special Palindrome

Statements

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).

Example

Input

137100

Output

12517
 1 #include <iostream>
 2 using namespace std;
 3 #define ll long long
 4
 5 ll dp[300][300];
 6 void fun(int n){
 7     for(int i=1;i<=n;i++)
 8         for(int j=1;j<=n;j++){
 9             if(i==1||j==1) dp[i][j] = 1;
10             else if(i>j) dp[i][j] = dp[i-j][j]+dp[i][j-1];
11             else if(i == j) dp[i][j] = dp[i][i-1]+1;
12             else dp[i][j] = dp[i][i];
13     }
14 }
15 ll n,m,ans=0;
16 int main(){
17     fun(251);
18     while(cin>>n){
19         if(n==0) return 0;
20         ans=0;
21
22         if(n&1){
23             for(int i=1; i<=n; i+=2){
24                 ans+=dp[(n-i)/2][i];
25             }
26             ans++;
27         }
28         else{
29             for(int i=2; i<=n; i+=2){
30                 ans+=dp[(n-i)/2][i];
31             }
32             ans+=dp[n/2][n/2];
33             ans++;
34         }
35         cout<<ans<<endl;
36     }
37     return 0;
38 }
39 /*
40 题意:一个从开始到中间是非递减的回文被称为特殊回文,
41 例如1123211,
42 定义F(N)为和为N的特殊回文的个数,
43 如F(1)=1,
44 即和为1的回文只有一个
45 就是 1,F(5)=7, (7), (1 5 1), (2 3 2), (1 1 3 1 1), (1 1 1 1 1 1 1),
46 求F(N),N小于等于250
47
48 思路:当N为偶数时,分2种情况,
49 第一种为回文的长度为奇数,
50 那么
51 最中间的数 m
52 一定是2 4 6 8......两边的数的和为(N-m)>>1,
53 对(N-m)>>1进行整数划分(m划分)
54 第二种为回文长度为偶数
55 则回文两边的和为N>>1,对N>>1整数划分(N>>1划分)
56 当N为奇数的时候只有一种情况,就是回文长度为奇数
57 最中间的数m为1 3 5 7....划分和上面一样
58
59 */
时间: 2024-11-05 18:49:41

Gym - 100952H Special Palindrome的相关文章

Gym 100952H Special Palindrome 非递减的回文串、dfs打表、查数列网站OEIS

H - H Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100952H Description standard input/output Statements A sequence of positive and non-zero integers called palindromic if it can be read the s

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

Codeforces Gym 100570 E. Palindrome Query Manacher

E. Palindrome QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100570/problem/E Description De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to its reverse. De Prezer also love

2016-2017 ACM-ICPC CHINA-Final

A Gym 101194A Number Theory Problem B Gym 101194B Hemi Palindrome C Gym 101194C Mr. Panda and Strips D Gym 101194D Ice Cream Tower E Gym 101194E Bet F Gym 101194F Mr. Panda and Fantastic Beasts G Gym 101194G Pandaria H Gym 101194H Great Cells I Gym 1

Gym 100570E : Palindrome Query

De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to its reverse. De Prezer also loves queries. You are given string s of length n and m queries. There are 3 types of queries : 1. 1px : Modify sp = x wher

【后缀数组|最长回文子串】URAL-1297 Palindrome

1297.Palindrome Time limit: 1.0 second Memory limit: 64 MB The "U.S. Robots" HQ has just received a rather alarming anonymous letter. It states that the agent from the competing ?Robots Unlimited? has infiltrated into "U.S. Robotics".

Ural 1297 Palindrome(Manacher或者后缀数组+RMQ-ST)

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrated into “U.S. Robotics”. «U.S. Robots»

URAL-1297 Palindrome (最长回文子串)

Palindrome Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Description The “U.S. Robots” HQ has just received a rather alarming anonymous letter. It states that the agent from the competing «Robots Unlimited» has infiltrat

URAL 1297 Palindrome 后缀数组

1297. Palindrome Time limit: 1.0 second Memory limit: 64 MB The "U.S. Robots" HQ has just received a rather alarming anonymous letter. It states that the agent from the competing ?Robots Unlimited? has infiltrated into "U.S. Robotics".