" Topic link " click here~~
" The main idea" gives you n toys, the stipulation only small toy sets in the big above, moreover is the specification increments successively, for example: 1->2->3, asks all toy sets to complete the minimum time which needs to spend
" problem-solving ideas ": only blame CF time too late, the day before night, the spirit a bit tired, the first question or after the game to do, hey ~ ~ can only say Taixu ~ ~
My approach: To find the sequence of 1, and then in turn to determine the following
Code:
#include <bits/stdc++.h>using namespace Std;const int N=1e6;int num[n];int n,m,k,t , Ans,cnt,res,top;int Pre,last,len;int Main () {while (scanf ("%d%d", &n,&m)!=eof) {int h1=0,res=0; int Q,o,ans; BOOL ok=0; while (m--) {scanf ("%d", &q); for (int i=1; i<=q; ++i) {scanf ("%d", &num[i]); if (num[i]==1) {ok=1; }} if (ok) {h1=1; for (int i=2; i<=q; ++i) {if ((num[i]) = = (num[i-1]+1)) h1++; else break; } res+=q-h1; ok=0; } else {res+=q-1; }} res+=n-h1; printf ("%d\n", res); } return 0;}
a way to see someone else:
The idea is clear, take come to borrow for a moment ~ ~
/*res: Record the longest satisfying condition that is the length of the monotonically increasing sequence (n-m-res+1): Each set of toys assumes the time required to disassemble all (N-res): The time of all toys re-set */#include <bits/stdc++.h>using namespace Std;const int N=1e6;int num[n];int n,m,k,t,ans,cnt,res,top;int pre,last,len;int Main () { cin>>n >>m; res=0; for (int i=0; i<m; ++i) { cin>>k; last=len=0; for (int i=0; i<k; ++i) { cin>>num[i]; if (num[i]==last+1) { last++; len++; } } Res=max (Res,len); } printf ("%d\n", (n-m-res+1) + (n-res));} /*INPUT3 1 3output1input7 1 3 6output8*/2 4 6output10input7 1 2 3 4
Codeforces #310ACase of Matryoshkas (analog)