Fipolaci NumeralTime limit:3000/1000ms (java/others) Memory limit:65535/65535kb (java/others) Submit Status
We define the following columns as Fipolaci:
F ( 1 ) = 1 " > F (1 ) = 1 f (1) =1
F(2)=2 F (2) =2
F(i) =f ( I−1 ) + F (i −2 ) (i >=3 ) /span> F (i) =f (i−1) +f (i−2) (i>=3)
Given any number, we can represent it as a sum of several distinct FIPOLACI numbers. For example, There are three representations of 13 .
= + ">13=13 13=13
= 5 + 8 ">13= 5+8 13=5+8
= 2 + 3 + 8 ">13=2+3< Span id= "mathjax-span-64" class= "Mo" >+8 13=2+3+8
Now give you a number nN, output the number of representations that represent the sum of several distinct FIPOLACI numbers.
Input
The first kind of a numberTt, representing the number of data groups, followed by T " >< Span id= "mathjax-span-72" class= "math" > t t line, one number per line n " >< Span id= "mathjax-span-75" class= "math" > n n.
T & #x2264; 5 ">t≤ 105 t≤105
1 & #x2264; N & #x2264; 5 ">1≤n ≤10 5 1≤n≤105
Output
Output t-T lines, one number per line, i.e. How many representations of n N.
Sample input and output
Sample Input |
Sample Output |
61234513 |
112123 |
Source
#include <iostream> #include <cstdio > #include <cstdlib> #include <cmath> #include <map> #include <vector> #include <queue> #include <cstring> #include <string> #include <algorithm>using namespace Std;typedef long ll; typedef unsigned long long ull, #define MM (A, B) memset (A,b,sizeof (a)), #define INF 0x7f7f7f7f#define for (I,N) for (int i=1;i <=n;i++) #define CT continue, #define PF printf#define SC scanfconst int mod=1000000007;const int N=1e5+100;int dp[n],a[ N];int Main () {MM (dp,0); a[1]=1;a[2]=2; int cnt=3; for (; a[cnt-1]<=1e5;cnt++) a[cnt]=a[cnt-1]+a[cnt-2]; cnt-=2; Dp[0]=1; for (int. i=1;i<=cnt;i++) for (int j=100000;j>=a[i];j--) dp[j]+=dp[j-a[i]; int N,cas; scanf ("%d", &cas); while (cas--) {scanf ("%d", &n); printf ("%d\n", Dp[n]); } return 0;
Error Analysis: This problem think of direct statistics, such as 1 has a composition, 2 has one, then because of 3=1+2, so 3 = two kinds of
5=2+3, so 5 also have two kinds ..... But it's not possible to handle digital reuse, like 13=5+8, but 5=3+2,8=5+3
In this case 3 is likely to be reused, but the number cannot be duplicated ... So there's no way.
So the statistics can not get through, it is only changed to construct, enumerate the Fibonacci number can be constructed out of the number, careful to find that Fibonacci number is probably more than 20 (within the <=1e5 range).
Cdoj 1133 The change of the direct statistics of the phenanthrene-Fibonacci