Topic Links:
http://acm.nefu.edu.cn/JudgeOnline/problemshow.php?problem_id=560
Main topic:
Given a natural number n, there is n starting to produce a set of half sets (n). Set (N) is defined as follows:
1) N is the element in set (n)
2) The natural number on the left side of N, but the natural number cannot exceed the half of the most recently added number.
3) Follow this rule until the natural number cannot be added.
For example: N = 6 o'clock, only the natural number not exceeding 6/2=3 is 1, 2, 3, which is 16, 26, 36. and 26,
36 You can continue to add 1, that is, 126, 136. Then Set (N) = {6, 16, 26, 126, 36, 136}.
Ideas:
Recursive addition, the number of Halfset (N) can be added, traverse 1~n/2,ans + = Halfset (i), pass
Get the answer. But this obviously repeats many of the same problems, using the array shu[] to save the results of the calculation, handing
When the result is present, the result value can be returned directly or the result value will be returned first.
AC Code:
#include <iostream>//#include <algorithm>//#include <cstdio>//#include <cstring>//using namespace Std;////int halfset (int n)//{//int ans = 1;//if (N > 1)//for (int i = 1; I <= n/2; ++i)//ans + = Halfset (i); /return ans; }////int Main ()//{//int N;//while (~scanf ("%d", &n))//{//printf ("%d\n", Halfset (N));//}////return 0;//} # include<iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std ; int shu[11000];int halfset (int N) {int ans = 1;if (Shu[n]) return shu[n];for (int i = 1; I <= n/2; ++i) ans + = Halfset (i); r Eturn Shu[n] = ans;} int main () {int n;while (~scanf ("%d", &n)) {printf ("%d\n", Halfset (N));} return 0;}
NEFU560 Half-Number set "recursion"