T1 Fibonacci
Given a series with the length of N, the number of I is \ (a_ I \), which requires division of the series.
The sum of any two numbers in a block is not in the Fibonacci sequence.
[Example input]
5
1 5 2 6 1 5 2 6 7
[Sample output]
4
[Example]
One of the optimal groups is: one of the optimal groups is: one of the optimal groups is {1}, {5, 2}, {6}, {7 }.
[Data Scope]
For 10% of the data, \ (n ≤ 20 \).
For 30% of data, \ (n ≤ 300 \).
For 60% of data, \ (n ≤ 1000 \).
For 100% of data, \ (n ≤ 100000, a_ I ≤ 10 ^ 9 \).
Analysis
\ (2 \ times a_ I \ le 2*10 ^ 9 \) although the range is large, the 47th items in the Fibonacci series are larger than this number !!
Since it is so small, it is not worthwhile to use a bucket to record whether each number is a number in the Fibonacci series. We can directly perform a brute-force query (two points can also be used.
In my test room, the train of thought is DP. \ (G [I] \) indicates that the maximum extended left direction of the I point is invalid to the \ (G [I] \) location.
We canEasyThis is pre-processed and stored in a map (it is said that it will be stuck), set, or hand hash table \ (1 ~ I-1 \) number, then enumerate each \ (FIB [J]-I \), query whether there is, take the nearest position.
Then and \ (G [I-1] \) to find the maximum value can be.
Then consider DP, \ (F [I] \) represents \ (1 ~ I \) Minimum number of groups.
Obviously \ (F [I] = min {f [I-K] + 1, G [I] \ le I-k \ le I-1 }\).
Then it is found that \ (O (N ^ 2) \) can not pass, you can use monotonous queue optimization, evenly spread a n, it is easy to pass.
I don't know why it gets stuck.
It is greedy.
Because it is obvious that the more groups there are, the more groups there will certainly be. We will keep adding a number to determine if it conflicts with the nearest group.
If there is a conflict, we will open a new group. Otherwise, we will join the previous group.
The hash table can be used for \ (O (1) \) queries, so that we can \ (O (n) \) solve the problem.
Code DP code (90 points)
# Include <iostream> # include <cstdio> # include <algorithm> # include <cstring> # include <map> # define ll long longusing namespace STD; const int maxn = 100009; ll read () {char C; ll num, F = 1; while (C = getchar (),! Isdigit (c) if (C = '-') F =-1; num = C-'0'; while (C = getchar (), isdigit (c )) num = num * 10 + C-'0'; return f * num;} ll fib [maxn], a [maxn], G [maxn]; ll f [maxn], d [maxn], Q [maxn], n, H = 1, t = 0; Map <int, int> m; bool ask (ll a); void Init (); int main () {freopen ("F. in "," r ", stdin); freopen (" F. out "," W ", stdout); Init (); For (INT I = 1; I <= N; I ++) {While (d [H] <G [I]) h ++; F [I] = Q [H] + 1; while (F [I] <= Q [T]) t --; Q [++ T] = f [I]; d [T] = I ;} cout <F [N] <Endl; Return 0;} bool ask (ll a) {int L = 1, R = 49, mid; while (L <= r) {mid = (L + r)> 1; if (FIB [Mid] = A) return 1; if (FIB [Mid] <A) L = Mid + 1; else r = mid-1 ;} return 0;} void Init () {fib [1] = 1; FIB [2] = 1; n = read (); For (INT I = 3; I <= 48; I ++) fib [I] = fib [I-1] + fib [I-2]; for (INT I = 1; I <= N; I ++) A [I] = read (); G [1] = 0; m [A [1] = 1; for (INT I = 2; I <= N; I ++) {int Pos = 0; For (Int J = 1; j <= 48; j ++) if (FIB [J]-A [I]> = 1 & M. find (FIB [J]-A [I])! = M. end () Pos = max (Pos, M [fib [J]-A [I]); G [I] = Pos; M [A [I] = I; G [I] = max (G [I-1], G [I]);} memset (F, 0x3f, sizeof (f); F [0] = 0; Q [++ T] = f [0]; d [T] = 0 ;} /* enumerate the first rabbit in the rabbit sequence before each rabbit * and run the DP command to find the minimum number of rabbits. * G [I] indicates the length expanded from I to the left. * We find that G [I] is incremental. We can consider monotonous queue optimization. * But it is preprocessed .. */
Greedy code (AC)
#include <iostream>#include <cstdio>#include <algorithm>#include <cstring>#include <cmath>#define ll long longusing namespace std;const int mod=133531;const int Maxn=100009;int read(){ char c;int num,f=1; while(c=getchar(),!isdigit(c))if(c=='-')f=-1;num=c-'0'; while(c=getchar(), isdigit(c))num=num*10+c-'0'; return f*num;}ll n,fib[Maxn],a[Maxn],ans=0;ll head[mod+100],nxt[mod+100],val[mod+100],tot=1;bool Find(int x){ int a=(x%mod+mod)%mod; for(int i=head[a];i;i=nxt[i]) if(val[i]==x)return 1; return 0;}void Clean(){ memset(head,0,sizeof(head)); tot=1;}void Insert(int x){ int a=(x%mod+mod)%mod; val[++tot]=x; nxt[tot]=head[a]; head[a]=tot;}int main(){ freopen("f.in","r",stdin); freopen("f.out","w",stdout); fib[1]=1;fib[2]=1;n=read(); for(int i=3;i<=48;i++)fib[i]=fib[i-1]+fib[i-2]; for(int i=1;i<=n;i++)a[i]=read(); Clean();Insert(a[1]);ans=1; for(int i=2;i<=n;i++){ for(int j=1;j<=47;j++){ if(fib[j]-a[i]>=1&&Find(fib[j]-a[i])){ ans++; //cout<<i<<endl; Clean(); break; } } Insert(a[i]); } printf("%lld\n",ans); return 0;}
T2
Given a heap of prime numbers (each with multiple numbers), multiply these prime numbers and the result must be smaller than R.
Calculate the number of solutions and the maximum value.
[Example input]
3 30
2 3 7
[Sample output]
28
16
[Data Scope]
For 30% 30% 30% 30% 1000000 data, $ K ≤ 10, r ≤ \(. For 60% 60% 60% 60% data, \) K ≤ 25, r ≤ 10 ^ 12 \(. For 100% 100% 100% 100% 100% 100 data, the data of \) K ≤ 25, r ≤ 10 ^ 18, P_ I ≤ $.
Analysis
The answer to the question \ (10 ^ 6 \) is the maximum value when 60 PTS is detected during brute force attacks.
You can get 60 points for a search.
The answer is about \ (10 ^ 12 \) at 100pts.
We can consider meet in mid.
Divide the data into two parts, search for the two sets separately, and calculate the corresponding product of the two sets.
We sort two sets. We can calculate the number of solutions whose product is smaller than R by double pointers.
Code brute force (60 points)
#include <iostream>#include <cstdio>#include <algorithm>#include <string>#define ll long longusing namespace std;ll read(){ char c;ll num,f=1; while(c=getchar(),!isdigit(c))if(c=='-')f=-1;num=c-'0'; while(c=getchar(), isdigit(c))num=num*10+c-'0'; return f*num;}ll k,r,p[109],now=1,ans=0,maxn;void dfs(int d){ if(d>k){ ans++; maxn=max(maxn,now); return ; } ll qwq=now; while(1){ if(now<r)dfs(d+1); else break; now*=p[d]; } now=qwq;}int main(){ freopen("h.in","r",stdin); freopen("h.out","w",stdout); k=read();r=read(); for(int i=1;i<=k;i++)p[i]=read(); dfs(1); printf("%lld\n%lld\n",maxn,ans); return 0;}
18.10.30 Shao 1 simulation Competition