Codeforces 946D Timetable

Source: Internet
Author: User

Timetable

Test instructions: Ivan is a student, their local week has n days, every day has M class, each class an hour, then ' 1 ' represents Ivan this time period needs class, now Ivan can skip the choice K class not to go on, he in school time for the day he chose the first lesson to the last class, That is, you can jump 2 end of the class, if the day without classes, the day will not need to go to school. Now, what is the minimum time for Ivan to go to school this week?

Solution: Calculate the total time not to skip class, and then use Group backpack (because there is only one case per day, so can only choose one in each group), run out of Class K section of the most truancy time is how much, the total time-truancy time is the answer.

Code:

1#include <bits/stdc++.h>2 using namespacestd;3 #defineLL Long Long4 #defineULL unsigned LL5 #defineFi first6 #defineSe Second7 #defineLson l,m,rt<<18 #defineRson m+1,r,rt<<1|19 #defineMax3 (A,B,C) max (A,max (b,c))Ten Const intINF =0x3f3f3f3f; One ConstLL mod = 1e9+7; Atypedef pair<int,int>PLL; - Const intN = 5e3+Ten; - CharStr[n]; the intDp[n]; - intPos[n]; - intLen[n]; - intN, M, K; + intMain () { -scanf"%d%d%d", &n, &m, &k); +     inttot =0; A      for(inti =1; I <= N; i++) { atscanf"%s", str+1); -         intCNT =0; -          for(intj =1; J <= M; J + +) -             if(Str[j] = ='1') -POS[++CNT] =J; -         if(CNT = =0)Continue; inmemset (Len,0,sizeof(len)); -         intLlen = pos[cnt]-pos[1]+1; toTot + =Llen; +          for(intto =1; To <= K && to <= CNT; to++){ -                  for(intr = cnt-to, L =1; R >= L && R <= CNT; r++, l++) theLen[to] = max (Len[to], Llen-(Pos[r]-pos[l] +1)); *                 if(To = =CNT) $Len[to] =Llen;Panax Notoginseng             } -          for(intj = k; J >=1; j--) the              for(intto =1; To <= J && to <= CNT; to++) +DP[J] = max (Dp[j], dp[j-to]+len[to]); A     } theprintf"%d", Tot-dp[k]); +     return 0; -}

Codeforces 946D Timetable

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.