Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define endl '\n'
- #define ll long long
- #define N 200009
- #define all(x) (x).begin(), (x).end()
- #define LL_INF (1LL << 62)
- #define INF (1 << 30)
- #define SetBit(x, k) (x |= (1LL << k))
- #define ClearBit(x, k) (x &= ~(1LL << k))
- #define CheckBit(x, k) ((x >> k) & 1)
- #define mod 1000000007
- // // // Coding starts from here...
- int n,m;
- vector<char>v={'n','a','r','e','k'};
- string s[1003];
- ll solve(int ind, int pos, int val){
- if(ind>n)return 0;
- int points=0,fl=0,cur=val,curPos=pos;
- for(int i=0;i<m;i++){
- if(s[ind][i]==v[curPos]){
- fl=1;
- int cnt=0;
- while(i<m && s[ind][i]=='k')cnt++,i++;
- if(cnt>0){
- cur+=cnt-1;
- points+=5-cur;
- cur=0;
- }
- curPos++;
- curPos%=5;
- }
- else if(fl)cur++;
- }
- if(!fl)return 0;
- ll res=0;
- res=max(res,points+solve(ind+1,curPos,cur));
- res=max(res,solve(ind+1,pos,val));
- cout<<ind<<" "<<pos<<" "<<val<<" "<<res<<endl;
- return res;
- }
- int main(void)
- {
- ios::sync_with_stdio(false);
- cin.tie(0);
- int t;cin>>t;
- while(t--){
- cin>>n>>m;
- for(int i=1;i<=n;i++){
- cin>>s[i];
- }
- cout<<solve(1,0,0)<<endl;
- for(int i=1;i<=n;i++)s[i].clear();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement