Gym 100952H Special palindrome non-descending palindrome string, Dfs play table, check the number of sites Oeis

Source: Internet
Author: User

H-HTime limit:MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u SubmitStatusPracticeGym 100952H

Description

Standard Input/output
Statements

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

15 2 6 4 6 2 15

20 3 1 1 3 20

We have a special kind of palindromic sequences and let's call it a special palindrome.

A palindromic sequence is a special palindrome if it 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 and 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 the sum of their values is N.

For example F (7) = 5 which is: (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 this 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).

Sample Input

Input
137100
Output
12517

Source

UESTC Summer Training #21

Gym 100952H


My Solution

Non-descending palindrome string, playing table

After the game to see the public code on our team is to play the table, others are normal, @@facesymbol@@‖∣ embarrassed

The sub-parity with DFS to make a non-descending left half string, and then find out this and Ans[sum + i]++;

For an even number of direct DFS, for odd numbers, enumerate mid, and then click Dfs

void Dfseven (int k, int sum) {    if (2*sum >) return;    cout<< "Here1" <<endl;    for (int i = k; I <=; i++) {        if (sum + i) <= {ans[2* (sum + i)]++; Dfseven (i, sum + i);}        else return;}    } void dfsodd (int mid, int k, int sum) {    if (2*sum + mid >) return;    cout<< "Here2" <<endl;    for (int i = k; I <=; i++) {        if (sum + i) + mid <= && I <= mid) {ans[2* (sum + i) + mid]++; dfso DD (Mid, I, sum + i);}        else return;}    }

And then only hit the former ans[50] and the previous, because the back of the relatively large time is not enough, so the first 50 of the table and then to the series of Web site Oeis Check, there is really,??

So put that first 250 ans into txt, and then write an intermediate program to convert the data into printf ("ans[%d] =%d;", I, Val), the way to the other TXT file, and then the complex paste to go up, tidy up just fine


Play the table code

#include <iostream> #include <cstdio> #include <cstring>using namespace std;typedef long Long ll;const    int MAXN = + 8;int ans[maxn];//even number of void Dfseven (int k, int sum) {if (2*sum >) return;    cout<< "Here1" <<endl;        for (int i = k; I <=; i++) {if (sum + i) <= {ans[2* (sum + i)]++; Dfseven (i, sum + i);}    else return;    }}void dfsodd (int mid, int k, int sum) {if (2*sum + mid >) return;    cout<< "Here2" <<endl; for (int i = k; I <=; i++) {if (sum + i) + mid <= && I <= mid) {ans[2* (sum + i) + mid]++; d        Fsodd (Mid, I, sum + i);}    else return;    }}int Main () {#ifdef LOCAL freopen ("A.txt", "R", stdin);    Freopen ("B.txt", "w", stdout);    #endif//LOCAL memset (ans, 0, sizeof ans);    ans[2]++;    Dfseven (1, 0);    ans[1]++;    for (int i = 1; i <=; i++) {dfsodd (i, 1, 0); } for (int i = 1; i <=; i++) {printf ("ans[%d] =%d;", I, ans[i] + 1);    }/* int n;    while (scanf ("%d", &n)) {printf ("%d", ans[n]); } */return 0;}

Final code

#include <iostream> #include <cstdio> #include <cstring>using namespace std;typedef long Long ll;const int MAXN = 250 + 8; LL Ans[maxn];int Main () {ans[1] = 1;ans[2] = 2;ans[3] = 2;ans[4] = 4;ans[5] = 3;ans[6] = 7;ans[7] = 5;ans[8] = 11;ans[9 ] = 8;ans[10] = 17;ans[11] = 12;ans[12] = 26;ans[13] = 18;ans[14] = 37;ans[15] = 27;ans[16] = 54;ans[17] = 38;ans[18] = 76 ; ans[19] = 54;ans[20] = 106;ans[21] = 76;ans[22] = 145;ans[23] = 104;ans[24] = 199;ans[25] = 142;ans[26] = 266;ans[27] = 1  92;ANS[28] = 357;ans[29] = 256;ans[30] = 472;ans[31] = 340;ans[32] = 621;ans[33] = 448;ans[34] = 809;ans[35] = 585;ans[36] = 1053;ans[37] = 760;ans[38] = 1354;ans[39] = 982;ans[40] = 1740;ans[41] = 1260;ans[42] = 2218;ans[43] = 1610;ans[44] = 2 818;ANS[45] = 2048;ans[46] = 3559;ans[47] = 2590;ans[48] = 4485;ans[49] = 3264;ans[50] = 5616;ans[51] = 4097;ans[52] = 701 8;ANS[53] = 5120;ans[54] = 8728;ans[55] = 6378;ans[56] = 10826;ans[57] = 7917;ans[58] = 13373;ans[59] = 9792;ans[60] = 164 84;ans[61] = 12076;ans[62] = 20236;ans[63] = 14848;ans[64] = 24793;ans[65] = 18200;ans[66] = 30275;ans[67] = 22250;ans[68] = 36886  ; ans[69] = 27130;ans[70] = 44810;ans[71] = 32992;ans[72] = 54329;ans[73] = 40026;ans[74] = 65683;ans[75] = 48446;ans[76] = 79265;ANS[77] = 58499;ans[78] = 95419;ans[79] = 70488;ans[80] = 114650;ans[81] = 84756;ans[82] = 137447;ans[83] = 101698; ANS[84] = 164496;ans[85] = 121792;ans[86] = 196445;ans[87] = 145578;ans[88] = 234221;ans[89] = 173682;ans[90] = 278720;ans [206848;ans[92] = 331143;ans[93] = 245920;ans[94] = 392722;ans[95] = 291874;ans[96] = 465061;ans[97] = 345856;ans[98 ] = 549781;ans[99] = 409174;ans[100] = 649019;ans[101] = 483330;ans[102] = 764959;ans[103] = 570078;ans[104] = 900373;ans[ [] = 671418;ans[106] = 1058191;ans[107] = 789640;ans[108] = 1242061;ans[109] = 927406;ans[110] = 1455820;ans[111] = 1087 744;ANS[112] = 1704261;ans[113] = 1274118;ans[114] = 1992458;ans[115] = 1490528;ans[116] = 2326608;ans[117] = 1741521;ans[ 118] = 2713398;ans[119]= 2032290;ans[120] = 3160899;ans[121] = 2368800;ans[122] = 3677789;ans[123] = 2757826;ans[124] = 4274556;ans[125] = 320708 6;ANS[126] = 4962526;ans[127] = 3725410;ans[128] = 5755174;ans[129] = 4322816;ans[130] = 6667228;ans[131] = 5010688;ans[13 2] = 7716070;ans[133] = 5802008;ans[134] = 8920663;ans[135] = 6711480;ans[136] = 10303379;ans[137] = 7755776;ans[138] = 11 888671;ANS[139] = 8953856;ans[140] = 13705118;ans[141] = 10327156;ans[142] = 15784173;ans[143] = 11899934;ans[144] = 18162 385;ANS[145] = 13699699;ans[146] = 20879933;ans[147] = 15757502;ans[148] = 23983452;ans[149] = 18108418;ans[150] = 2752428 0;ANS[151] = 20792120;ans[152] = 31561603;ans[153] = 23853318;ans[154] = 36160845;ans[155] = 27342421;ans[156] = 41397124; ANS[157] = 31316314;ans[158] = 47353396;ans[159] = 35839008;ans[160] = 54124796;ans[161] = 40982540;ans[162] = 61816437;an S[163] = 46828032;ans[164] = 70548311;ans[165] = 53466624;ans[166] = 80453313;ans[167] = 61000704;ans[168] = 91682668;ans[ 169] = 69545358;ans[170] = 104403741;ans[171] = 79229676;ans[172] = 118806744;ans[173] = 90198446;ans[174] = 135102223;ans[175] = 102614114;ans[17 6] = 153528658;ans[177] = 116658616;ans[178] = 174350347;ans[179] = 132535702;ans[180] = 197865953;ans[181] = 150473568;an S[182] = 224406247;ans[183] = 170727424;ans[184] = 254344551;ans[185] = 193582642;ans[186] = 288094273;ans[187] = 21935831 5;ANS[188] = 326120818;ans[189] = 248410816;ans[190] = 368939881;ans[191] = 281138048;ans[192] = 417130912;ans[193] = 3179  84256;ANS[194] = 471335560;ans[195] = 359444904;ans[196] = 532274004;ans[197] = 406072422;ans[198] = 600743477;ans[199] = 458482688;ANS[200] = 677637038;ans[201] = 517361670;ans[202] = 763943462;ans[203] = 583473184;ans[204] = 860768675;ans[2 [] = 657667584;ans[206] = 969336374;ans[207] = 740890786;ans[208] = 1091013811;ans[209] = 834194700;ans[210] = 1227313238 ; ans[211] = 938748852;ans[212] = 1379921672;ans[213] = 1055852590;ans[214] = 1550704877;ans[215] = 1186949056;ans[216] = 1 741741564;ans[217] = 1333640710;ANS[218] = 1955329266;ans[219] = 1497705768;ans[220] = 2194025352;ans[221] = 1681116852;ans[222] = 2460655086;ans[ 223] = 1886061684;ans[224] = 2758359212;ans[225] = 2114965120;ans[226] = 3090606588;ans[227] = 2370513986;ans[228] = 34612 49193;ANS[229] = 2655684608;ans[230] = 3874538905;ans[231] = 2973772212;ans[232] = 4335193118;ans[233] = 3328423936;ans[ 234] = 4848416380;ans[235] = 3723675326;ans[236] = 5419976831;ans[237] = 4163989458;ans[238] = 6056235989;ans[239] = 46543 00706;ANS[240] = 6764237552;ans[241] = 5200062976;ans[242] = 7551745299;ans[243] = 5807301632;ans[244] = 8427348786;ans[ 245] = 6482671322;ans[246] = 9400510845;ans[247] = 7233519619;ans[248] = 10481691022;ans[249] = 8067955712;ans[250] = 1168    2407480;    int n;        while (scanf ("%d", &n)) {if (n = = 0) break;    printf ("%i64d\n", Ans[n]); } return 0;}

Thank you!

------ from Prolights

Gym 100952H Special palindrome non-descending palindrome string, Dfs play table, check the number of sites Oeis

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.