SRM 653 Countrygrouphard
Test instructions
n the individual sits in a row, sitting with the people of the same country, the reporter asks some people how many people they have in their country, and they all answer the right message. There is an AI person in the country where each message is known as the Pi position, and it is known whether the information can infer the situation of the country in which all people belong.
Analysis:
F[i] Indicates the number of scenarios to the first position. Then enumerate how many people in the back belong to a country. When the f[i]>2, set to 2 on the line. Initializes the f[n]=1.
Code:
1 /*2 * @Author: MJT3 * @Date: 2018-10-17 20:55:424 * @Last Modified BY:MJT5 * @Last Modified time:2018-10-17 21:37:106 */7#include <cstdio>8#include <algorithm>9#include <cstring>Ten#include <cmath> One#include <iostream> A#include <cctype> -#include <Set> -#include <vector> the#include <queue> -#include <map> - #defineFi (s) freopen (S, "R", stdin); - #defineFo (s) freopen (S, "w", stdout); + using namespacestd; -typedefLong LongLL; + AInlineintRead () { at intx=0, f=1;CharCh=getchar (); for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') f=-1; - for(; isdigit (ch); Ch=getchar ()) x=x*Ten+ch-'0';returnx*F; - } - - classcountrygrouphard{ - Public: in intf[ the]; - stringSolve (Vector <int>a) { to intn =a.size (); +F[n] =1; - for(inti = n-1; I >=0; --i) { the if(A[i] = =0) { * intOK =-1; $ for(intj =1; (i + j) <= N; ++j) {Panax Notoginseng if(A[i + J-1] !=0) {//the last few places . - if(OK! =-1&& OK! = a[i + J-1]) Break; the ElseOK = a[i + J-1]; + } A if(OK = =-1|| OK = = j) F[i] + + f[i +j]; the } + } - Else { $ BOOLOK = (i + a[i] > N);//requires a[i] equal to the back $ for(intj = i; J < N && J < i + a[i]; ++j) - if(A[j] && a[j]! = a[i]) OK =true; - if(!ok) F[i] = F[i +A[i]]; the } - if(F[i] >=2) F[i] =2;Wuyi } the returnf[0] >1?"Insufficient":"sufficient"; - } Wu -};
SRM 653 Countrygrouphard