A. Dreamoon and stairs
Exercises
First write as much as 2 steps, and then judge whether can%m, can not add the smallest number so that it can%m on the line
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intn=1e5+Ten;Const intm=1e3+Ten;Const intmod=1e9+7;Const intinf=1e9+Ten;intn,m;intMain () {intn,m; CIN>>n>>m; if(n<m) cout<<-1<<Endl; Else{ intans=n/2+ (n%2==0?0:1); if(ans%m==0) cout<<ans<<Endl; Else{ for(intI=1; i<m;i++){ if((ans+i)%m==0) {cout<<ans+i<<Endl; Break; } } } }}
B.dreamoon and WiFi
Exercises
Simple DP, just a recursive search, please.
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intn=1e5+Ten;Const intm=1e3+Ten;Const intmod=1e9+7;Const intinf=1e9+Ten;strings1,s2;intCnt1,cnt,len;voidDP (intPosintc) { if(pos==Len) { if(C==CNT1) cnt++; return; } if(s2[pos]=='+') DP (pos+1, c+1); if(s2[pos]=='-') DP (pos+1, C-1); if(s2[pos]=='?') {DP (pos+1, C-1); DP (POS+1, c+1); }}intMain () {CIN>>s1>>S2; Cnt1=0, cnt=0; Len=s1.length (); for(intI=0; i<len;i++)if(s1[i]=='+') cnt1++;Elsecnt1--; intsum=1; for(intI=0; i<len;i++)if(s2[i]=='?') sum*=2; DP (0,0); cout<<setprecision ( the) << (Double) cnt/(Double) sum<<Endl; return 0;}
C.dreamoon and Sums
Exercises
Notice that the x/b=x/b*b+x%b is fine. Then note that each calculation location is calculated to take mod ....
Code:
#include <bits/stdc++.h>using namespacestd;#definePB Push_back#defineMP Make_pair#defineSe Second#defineFS First#defineLL Long Long#defineCLR (x) memset (x,0,sizeof x)#defineMC (x, y) memcpy (x,y,sizeof (×))#defineSZ (x) ((int) (x). Size ())#definefor (It,c) for (__typeof ((c). Begin ()) it= (c). Begin (); it!= (c). end (); it++)#defineLson l,m,rt<<1#defineRson m+1,r,rt<<1|1typedef pair<int,int>P;Const Doubleeps=1e-9;Const intn=1e5+Ten;Const intm=1e3+Ten;ConstLL mod=1000000007;Const intinf=1e9+Ten; LL A, B;intMain () {CIN>>a>>b; LL k= ((1ll+a) *a/2%mod*b%mod+a)%MoD; LL sum=0; for(LL i=1; i<b;i++) {sum+=i*K; Sum%=MoD; } cout<<sum<<Endl;}
D. Dreamoon and sets
Exercises
Regular problem, not much to say
Code:
#include <iostream>using namespacestd;intMain () {intn,k; CIN>>k>>N; cout<< (6*k-1) *n<<Endl; for(intI=0; i<k;i++) cout<<n* (6*i+1) <<" "<<n* (6*i+2) <<" "<<n* (6*i+3) <<" "<<n* (6*i+5) <<Endl;}
E. Dreamoon and Strings
Exercises
Violence handles each position, from the back to the front of the first template's location, and then DP handles
Reference Blog http://www.cnblogs.com/qscqesze/p/5794709.html
Code:
//Coding by Qscqesze#include <bits/stdc++.h>using namespacestd;Const intMAXN =2005;CharS1[MAXN],S2[MAXN];intDP[MAXN][MAXN];intLen1,len2;intSolveintx) { if(X<LEN2)returnMAXN; inta=x,b=len2,tmp=0; while(a&&b) {if(S1[a]==s2[b]) a--, b--; Elsetmp++,a--; } if(b==0)returntmp; Else returnMAXN;}intMain () {scanf ("%s%s", s1+1, s2+1); Len1= strlen (s1+1); Len2= strlen (s2+1); for(intI=0; i<=len1;i++) for(intj=0; j<=len1;j++) if(j>i) dp[i][j]=- the; for(intI=1; i<=len1;i++) { intx=solve (i); for(intk=0; k<=len1;k++) Dp[i][k]=max (dp[i][k],dp[i-1][k]); for(intk=0; k<=len1;k++)if(x<=k) Dp[i][k]=max (dp[i][k],dp[i-x-len2][k-x]+1); } for(intI=0; i<=len1;i++) printf ("%d", Dp[len1][i]); printf ("\ n");}
Codeforces Round #272 (Div. 2) ABCDE