Computing of the wikioi ladder of 1011 (memory recursion)

Source: Internet
Author: User

Description Description

We need to find the number of numbers with the following properties (including the natural number N of the input ):

Enter a natural number n (n <= 1000), and then process the natural number as follows:

1. No processing;

2. Add a natural number to its left, but the natural number cannot exceed half of the original number;

3. After the number is added, continue to process according to this rule until the natural number cannot be added.

Input description Input description

N

Output description Output description

Number of conditions

Sample Input Sample Input

6

Sample output Sample output

6

Data range and prompt Data size & hint

The six numbers are:

6

16

26

126

36

136


I haven't forgotten the recursive question for a long time. I just met this question by swiping the ladder ......

At the beginning, I thought that recursion was still afraid of timeout. Later I felt that the memory should be okay, and then I wrote it. I tried the maximum n = 1000 seconds before I was relieved ......

#pragma comment(linker, "/STACK:1024000000,1024000000")#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<map>#include<queue>#include<set>#include<cmath>#include<bitset>#define mem(a,b) memset(a,b,sizeof(a))#define lson i<<1,l,mid#define rson i<<1|1,mid+1,r#define llson j<<1,l,mid#define rrson j<<1|1,mid+1,r#define INF 1000000007#define seed 13131#define seed1 1313#define maxn 500005typedef long long ll;typedef unsigned long long ull;using namespace std;ll a[1005];ll dfs(int n){    if(!n||n==1) return 0;    if(a[n]) return a[n];    ll sum=n/2;    for(int i=n/2;i>1;i--)        sum+=(a[i]=dfs(i));    return sum;}int main(){    int n;    cin>>n;    cout<<dfs(n)+1<<endl;    return 0;}


Computing of the wikioi ladder of 1011 (memory recursion)

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.