Topic Address: POJ 2229
: Given a positive integer, how many ways to write it as a number of 2 power and
thinking: You can use recursion, for an integer n, divided into odd and even, we should discuss the situation.
1. If it is odd, then there must be a 1 in this representation, minus this 1, which is n-1
that is dp[n]=dp[n-1].
2. If an even number, then there are two cases, there are 1 and No 1. For 1 of cases, it is possible to split two 1 directly and then become n-2. In the case of No 1, it can be directly converted to N/2, because n splits all the numbers are multiples of 2, just divide the numbers in each split result by 2 to correspond to a split of the N/2.
#include <stdio.h> #include <math.h> #include <string.h> #include < stdlib.h> #include <iostream> #include <sstream> #include <algorithm> #include <set> # Include <queue> #include <stack> #include <map> #include <bitset> #pragma comment (linker, "/
stack:102400000,102400000 ") using namespace std;
typedef __int64 LL;
const int inf=0x3f3f3f3f;
Const DOUBLE pi= ACOs (-1.0);
const double esp=1e-6;
using namespace Std;
const int MAXN=1E6+10;
const int mod=1000000000;
int DP[MAXN];
int main () {int n;
Dp[1]=1;
dp[2]=2;
for (int i=3;i<maxn;i++) {if (i&1) Dp[i]=dp[i-1]%mod;
else dp[i]= (dp[i-2]+dp[i>>1])%mod;
while (~SCANF ("%d", &n)) {printf ("%d\n", Dp[n));
return 0; }