//限制:有m次使用魔法的机会,可以将不同比赛的两道题目互相交换位置
https://www.codechef.com/CHN15MOS/problems/CHN03
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define REP(i,a,b) \ for (int i=int(a);i<=int(b);i++) // a to b, and variable i is local! #define TR(c,it) \ for (auto it=(c).begin();it != (c).end();it++) #define s(x) scanf("%d",&x) #define sl(x) scanf("%lld",&x) #define pb push_back #define mp make_pair #define fi first #define se second #define set0(a) memset(a,0,sizeof(a)) #define setdp(a) memset(a,-1,sizeof(a)) #define INF 2000000000 #define MOD 1000000007 int n,times,k; int dp[52][52][52][52],t[3][52],p[3][52]; int fnc(int pos,int tim,int swaps,int solved){ if (tim>times||swaps>k||solved>n) return -INF; if (pos>n) return 0; if (dp[pos][tim][swaps][solved] != -1) return dp[pos][tim][swaps][solved]; dp[pos][tim][swaps][solved]=0; int mx=0,cnt,t1,pl; REP (mask,0,7){ cnt=t1=pl=0; REP (i,0,2){ if ((1<<i)&mask){ cnt++; t1+=t[i][pos]; pl+=p[i][pos]; } } mx=max(mx,fnc(pos+1,tim+t1,swaps+max(0,cnt-1),solved+cnt)+pl); } dp[pos][tim][swaps][solved]=mx; return mx; } int main(){ int tt; s(tt); while (tt--){ s(n); s(k); s(times); k=min(k,n); REP (i,1,n){ s(t[0][i]); s(t[1][i]); s(t[2][i]); } REP (i,1,n){ s(p[0][i]); s(p[1][i]); s(p[2][i]); } setdp(dp); cout<<fnc(1,0,0,0)<<endl; } return 0; }
有n张牌排成一列,每张牌有两面(R和B),初始有一个放置方法,A和B博弈,从A开始每一次可以选取一张R朝上的牌和紧跟着它的任意多张连续B朝上的牌,并把它们都翻面(R变B,B变R),他们都会选择最优的做法,当没有R可以翻的时候那一方就输了。求最后输的是谁。
Replace all B
s with $0$s and R
s with $1$s, and interpret the string as a binary number. If this number is divisible by $3$, then the second player wins. Otherwise, the first player wins.
https://www.codechef.com/CHN15MOS/problems/CHN07
int sum(string S){ int res=0,pow=1; for(int i=S.size()-1;i>=0;i--){ if(S[i]=='R'){ res+=pow; } pow=0-pow; } res=res%3; if(res<0){ res+=3; } return res; } int main(int argc,char const *argv[]){ std::ios_base::sync_with_stdio(false); int T; string S; cin>>T; while(T-->0){ cin>>S; if(sum(S)%3==0){ cout<<"Animesh"<<endl; } else{ cout<<"Malvika"<<endl; } } return 0; }