In the morning, took a test, noip2011d2 the problem, only 150 ....
T1 is a water problem, I draw on the draft paper can be launched, to use the Yang Hui triangle.
T2 a little bit of nonsense. Original question http://www.codevs.cn/problem/1138/
I look at the data is very large, this thought is a high-level data structure, but I do not write and ran a two points + violence, want to go unexpectedly 50 points, they write high-level data structure no points. Positive solutions are two points + prefixes for optimal violence. Run through all the minerals at each check to get the prefix, then cycle through each interval, with (r)-(L-1).
T3 is a greedy problem, very good greedy topic. Original question http://www.codevs.cn/problem/1139/
First of all, the greedy strategy must be to use accelerators when people are many. But did you wait for someone at the next intersection after using the accelerator? If you wait, it uses the same effect as useless. We can preprocess each station to the next not to wait for the location of the station, record the number of each station alight, with the prefix and, minus to get in a certain stage of the car number. Loop to find the most people on the road and do not have to wait, ans minus the number, so we know the need to loop through K to consume all the accelerator.
PS: Can not consume a lot of accelerators at a time, because each time the accelerator is exhausted, the car needs to wait for the relative change of the station, so only one accelerator at a time.
Then, in the afternoon, I learned the digits DP.
The key to digital DP is to consider the limitations, memory search, from high to low to search, or relatively see (better than the suffix array, at least I think so). Key: Think of numbers as a string
Here are two questions to be written on the night.
1. How many of the numbers that contain 13 and are divisible by 13
A bare question, plus a limit indicating whether the current one has appeared in 13, plus a limit indicating to this bit mod
CODE:
1#include <cstdio>2#include <iostream>3#include <cstring>4#include <algorithm>5 using namespacestd;6 intbit[ the],dp[ the][ the][3];7 intRead () {8 CharCintf=1, x=0; c=GetChar ();9 while(c>'9'|| c<'0'){if(c=='-') f=-1; c=GetChar ();}Ten while(c<='9'&&c>='0') x=x*Ten+c-'0', c=GetChar (); One returnf*x; A } - - intDfsintPosintMoDintHaveintlimit) { the if(!pos)returnmod==0&&have==2; - if(!limit&&dp[pos][mod][have]!=-1)returnDp[pos][mod][have]; - intNum=limit?bit[pos]:9; - inth,m,ans=0; + for(intI=0; i<=num;i++){ -M= (mod*Ten+i)% -; h=have ; + if(have==0&&i==1) h=1; A if(have==1&&i!=1) h=0; at if(have==1&&i==3) h=2; -Ans+=dfs (pos-1, m,h,limit&&i==num); - } - if(!limit) dp[pos][mod][have]=ans; - returnans; - } in - intMain () { to intN,len; + while(SCANF ("%d", &n)! =EOF) { -memset (dp,-1,sizeof(DP)); thememset (bit,0,sizeof(bit)); *len=0; $ while(n) {Panax Notoginsengbit[++len]=n%Ten; -N/=Ten; the } +printf"%d\n", DFS (Len,0,0,1)); A } the + return 0; -}
View Code
2. Balance Number
Enumeration as the position of the number of pivots, recorded to the current position of the and, if the last and 0, then is the balance number
CODE:
1 /*2 notes:3 bit[++len]=n%10; 46 line should be for (int i=1;i<=len;i++) Ans+=dfs (len,i,0,1);4 26 lines should be if (pos==-1) ...5 why?? I also want to ask why:6 7 array size Others len++ less than themselves with one8 9 */Ten#include <cstdio> One#include <iostream> A#include <cstring> -#include <algorithm> - #defineINF 2147483647 the using namespacestd; - intbit[ -]; - Long Longdp[ -][ -][2005]; - Long LongRead () { + CharCintf=1;Long Longx=0; c=GetChar (); - while(c>'9'|| c<'0'){if(c=='-') f=-1; c=GetChar ();} + while(c<='9'&&c>='0') x=x*Ten+c-'0', c=GetChar (); A returnf*x; at } - - Long LongDfsintPosintOintSumintlimit) { - if(pos==0)returnsum==0; - if(sum<0)return 0; - if(!limit&&dp[pos][o][sum]!=-1)returnDp[pos][o][sum]; in intNum=limit?bit[pos]:9;Long Longans=0; - for(intI=0; i<=num;i++){ to intnext=sum; +next+= (pos-o) *i; -Ans+=dfs (pos-1, o,next,limit&&i==num); the } * if(!limit) dp[pos][o][sum]=ans; $ returnans;Panax Notoginseng } - the Long LongSolveLong LongN) { + intlen=0; A while(n) { thebit[++len]=n%Ten; +N/=Ten; - } $ Long Longans=0; $ for(intI=1; i<=len;i++) Ans+=dfs (Len,i,0,1); - returnans-len+1; - } the - intMain () {Wuyi intT; thescanf"%d",&T); -memset (dp,-1,sizeof(DP)); Wu while(t--){ - Long LongL,r; AboutCin>>l>>R; $Cout<<solve (R)-solve (l1) <<Endl; - } - return 0; -}
View Code
Ah! Go to the exam tomorrow, after the test will learn the routine, good TM fear ah ....
"Fifth day of training, exam + digital" Exam really does not use algorithm ~~~~~~~~~