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)