大意: n天, 每天m小时, 给定课程表, 每天的上课时间为第一个1到最后一个1, 一共可以逃k次课, 求最少上课时间.

每天显然是独立的, 对每天区间dp出逃$x$次课的最大减少时间, 再对$n$天dp即可.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head #ifdef ONLINE_JUDGE
const int N = 510;
#else
const int N = 111;
#endif int n, m, k, tot;
char s[N][N];
int f[N][N], g[N][N], dp[N][N];
int main() {
scanf("%d%d%d", &n, &m, &k);
REP(i,1,n) scanf("%s",s[i]+1);
REP(i,1,n) {
vector<int> v;
REP(j,1,m) if (s[i][j]=='1') v.pb(j);
int sz=v.size();
if (sz) {
memset(dp,0,sizeof dp);
v.insert(v.begin(),0);
PER(len,1,sz-1) {
REP(L,1,sz+1-len) {
int R = L+len-1;
if (L!=1) dp[L][R]=max(dp[L][R],dp[L-1][R]+v[L]-v[L-1]);
if (R!=sz) dp[L][R]=max(dp[L][R],dp[L][R+1]+v[R+1]-v[R]);
f[i][sz-len]=max(f[i][sz-len],dp[L][R]);
}
}
f[i][sz] = f[i][sz-1]+1;
tot += v[sz]-v[1]+1;
}
REP(j,0,k) REP(jj,0,min(j,sz)) {
g[i][j]=max(g[i][j],g[i-1][j-jj]+f[i][jj]);
}
}
printf("%d\n", tot-g[n][k]);
}

最新文章

  1. zerojs! 造出最好的 CMS 轮子
  2. Linux 命令基础合集
  3. Android和Linux应用综合对比分析
  4. 【Alpha版本】 第五天 11.11
  5. 微信开发时遇到的UrlConnection乱码的问题
  6. php join函数使用,很是方便
  7. 生成dll文件的示例
  8. N - Tram - poj1847(简单最短路)
  9. Prime邻接表+优先队列
  10. eclipse 搭建Robotium环境--apk 环境搭建
  11. Spring Cloud官方文档中文版-客户端负载均衡:Ribbon
  12. HDU 1228(字符串处理)
  13. LeetCode第二十二题-创建n对括号
  14. 为你揭秘知乎是如何搞AI的——窥大厂 | 数智方法论第1期
  15. mysql读写分离——中间件ProxySQL的简介与配置
  16. File类基本用法
  17. weblogic 乱码
  18. 单片机中printf函数的重映射
  19. JS 日期比较方法
  20. Shell IF条件判断解析

热门文章

  1. ZooKeeper 简介说明
  2. python学习之路(5)
  3. 微信小程序-获取当前位置
  4. 移动端 iphone手机在中文情况下不执行keyup事件
  5. legend3---4、lavarel中session使用注意
  6. vmx转换ofv模板,导入esxi
  7. jquery 登录判断遇到的小问题
  8. DeepFaceLab:手动提取高精度脸图,减少抖动!
  9. python自然语言处理学习笔记2
  10. 在Tomcat中配置MySQL数据源