#分组背包 Educational codeforces Round (rated for Div. 2) D. Timetable

Source: Internet
Author: User

2018-03-11

Http://codeforces.com/contest/946/problem/D

D. TimetableTime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Ivan is a student at Berland state University (BSU). There is n days in Berland week, and each of the these days Ivan might has some classes at the university.

There is m working hours during each Berland day, and all lesson at the university LA STS exactly one hour. If at some day Ivan's first lesson is during i -th hour, and the last lesson are during J -th Hour, then he spends J ?-? I ? +?1 hours in the university during this day. If There is no lessons during some day, then Ivan stays at home and therefore spends 0 hours in th E University.

Ivan doesn ' t like to spend a lot of time in the university, so he had decided to skip some lessons. He cannot skip more than K lessons during the week. After deciding which lessons he should skip and which he should attend, every day Ivan would enter the university right BEF Ore the start of the first lesson he does not skip, and leave it after the end of the last lesson he decides to attend. If Ivan skips all lessons during some day, he doesn ' t go to the university.

Given n, m, k and Ivan ' s timetable, can you determine the minimum number of hours h e have to spend in the university during one week, if he cannot skip more than k lessons?

Input

The first line contains three integers n , m and Span class= "Tex-span" > K (1?≤? N ,? m ? ≤?500, 0?≤? K ? ≤?500)-the number of days in the Berland week, the number of working hours during each day, and the number of Les Sons Ivan can skip, respectively.

Then n lines follow, i-th line containing a binary string of m characters. If J-th character in I-th line are 1, then Ivan have a lesson on i-th Day dur ing J-th Hour (if it is 0, there is no such lesson).

Output

Print the minimum number of hours Ivan have to spend in the university during the week if he skips isn't more than K Lessons.

ExamplesInput
2 5 1
01001
10110
Output
5
Input
2 5 0
01001
10110
Output
8
Note

In the first example Ivan can skip any of the lessons during the first day, so he spends 1 hour during the first day a nd 4 hours during the second day.

In the second example Ivan can ' t skip any lessons, so he spends 4 hours every day.

idea : Although know when backpack, but no idea, direct poke others solution: https://www.cnblogs.com/ZERO-/p/8530982.html

Some reflective study, some should not appear errors will still appear. Increase the number of brush and brush problem frequency, more importantly, always learn to consolidate the algorithm.

1.CF Display compication error may be a header file errors, such as the problem of forgetting to write CString and use the Memset function;

2. Because the input is a number with no spaces attached, it is first to be treated as a character;

3. Array cross-border issues;

4. All the classes that have been sentenced for one day have escaped;

5. When the backpack is written, the calculated minimum value is converted to the maximum value;

6.* how to pre-processing each group of each class of the minimum number of days (distance), do not grasp the words, even know what algorithm also make not out;

7.* Study Group backpack;

Code

1#include <cstring>2#include <cstdio>3#include <algorithm>4#include <iostream>5#include <vector>6#include <queue>7 using namespacestd;8 #defineMAXN 5059 #defineFi firstTen #defineSe Second One #definell Long Long A  inth[505][505],p[505][505]; -     intnum[505]; -     inta[505][505]; the     intdp[505]; -     intn,m,k; -     Chars[505][505];  - intMain () + {     -     +  ACin>>n>>m>>K; atmemset (NUM,0,sizeof(num)); -      for(intI=0; i<n;i++) -Cin>>S[i]; -      for(intI=0; i<n;i++) -     {  -        for(intj=0; j<m;j++) in       { -h[i][j]=s[i][j]-'0'; to        if(h[i][j]==1) +{num[i]++;a[i][num[i]]=j;}//a[] The location of the deposit number 1 -          the       } *     }   $       for(intI=0; i<n;i++)//The first few rowsPanax Notoginseng      { -          inttmp=min (k,num[i]); the           for(intj=0; j<=tmp;j++)//The following requirements corresponding to the shortest distance of truancy, J is the choice of truancy number J may be 0 +          { AP[I][J]=MAXN;//the shortest distance is stored in P the             if(J==num[i])//easy to delay: when the whole day to go to the course of the escape, the distance is 0, to special sentence +p[i][j]=0; -            Else      $              for(intv=1; v<=j+1; v++)//V is the lesson on the first few SectionTo $             { -P[i][j]=min (p[i][j],a[i][v+num[i]-j-1]-a[i][v]+1);  -                }      the         } -       }Wuyill sum=0; the        for(intI=0; i<n;i++) -sum+=p[i][0]; WuMemset (DP,0,sizeof(DP));  -        for(intI=0; i<n;i++) About      //Group Backpack $         for(intj=k;j>=0; j--)  -          for(intv=0; V<=min (K,num[i]); v++)         -          if(J&GT;=V)//not written at first, the array may be out of bounds, written on the right ...  -Dp[j]=max (dp[j-v]+p[i][0]-p[i][v],dp[j]); Acout<<sum-Dp[k];  +         the}

#分组背包 Educational codeforces Round (rated for Div. 2) D. 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.