【2005-2006 ACM-ICPC, NEERC, Moscow Subregional Contest】Problem J. Jack-pot
简单dfs,差分一下A数组和建出字典树能写得更方便,若不这么做代码时就会像我一样难受。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N = 100003;
int a[13][N], n, m, k, A[13], pos[13][N];
ll dfs(int tmp, int l, int r, int f) {
if (tmp > m) {
return 1ll * (r - l + 1) * A[m];
}
int und = l;
ll ans = 1000000000000000ll;
if (r - l + 1 < k || (a[tmp][l] != 0) || (a[tmp][r] != k - 1)) {
ans = 1ll * A[tmp - 1] * (r - l + 1);
if (a[tmp][l] != 0) pos[tmp - 1][f] = 0;
if (a[tmp][r] != k - 1) pos[tmp - 1][f] = -(k - 1);
}
for (int i = l + 1; i <= r; ++i)
if (a[tmp][i] != a[tmp][i - 1] && a[tmp][i] != a[tmp][i - 1] + 1) {
ans = 1ll * A[tmp - 1] * (r - l + 1);
pos[tmp - 1][f] = -(a[tmp][i - 1] + 1);
break;
}
for (int i = l + 1; i <= r + 1; ++i)
if (i > r || a[tmp][i] != a[tmp][und]) {
int num = dfs(tmp + 1, und, i - 1, und) + 1ll * A[tmp - 1] * (r - l + 1 - (i - und));
if (num < ans) {
ans = num;
pos[tmp - 1][f] = und;
}
und = i;
}
return ans;
}
char s[13];
int main() {
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= m; ++i) scanf("%d", &A[i]);
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
for (int j = 1; j <= m; ++j)
a[j][i] = s[j] - '0';
}
ll ans = dfs(1, 1, n, 1); int tmp = 1;
for (int i = 1; i <= m; ++i) {
tmp = pos[i - 1][tmp];
if (tmp <= 0) {
printf("%d", -tmp);
for (int j = i + 1; j <= m; ++j) putchar('0');
break;
}
printf("%d", a[i][tmp]);
}
printf("\n%lld\n", ans);
return 0;
}
【2005-2006 ACM-ICPC, NEERC, Moscow Subregional Contest】Problem J. Jack-pot的更多相关文章
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 G. Garden Gathering
Problem G. Garden Gathering Input file: standard input Output file: standard output Time limit: 3 se ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 D. Delay Time
Problem D. Delay Time Input file: standard input Output file: standard output Time limit: 1 second M ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest
目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...
- Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest
2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...
- 2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic(Kruskal思想)
2016 NEERC, Moscow Subregional Contest K. Knights of the Old Republic 题意:有一张图,第i个点被占领需要ai个兵,而每个兵传送至该 ...
- 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution
从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 K. King’s Rout
K. King's Rout time limit per test 4 seconds memory limit per test 512 megabytes input standard inpu ...
- ACM ICPC 2015 Moscow Subregional Russia, Moscow, Dolgoprudny, October, 18, 2015 I. Illegal or Not?
I. Illegal or Not? time limit per test 1 second memory limit per test 512 megabytes input standard i ...
随机推荐
- Django-Form表单(验证、定制、错误信息、Select)
Django form 流程 1.创建类,继承form.Form 2.页面根据类的对象自动创建html标签 3.提交,request.POST 封装到类的对象里,obj=UserInf ...
- Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
问题: 当我们打开数据库,即use dbname时,要预读数据库信息,当使用-A参数时,就不预读数据库信息. 解决方法:mysql -hhostname -uusername -ppassword - ...
- Jenkins远程调度Shell命令
http://blog.csdn.net/fireofjava/article/details/40624353 Jenkins服务器为Win7版本,需要远程调用CentOS服务器上Shell脚本,然 ...
- 做了这么久的 DBA,你真的认识 MySQL 数据安全体系?【转】
给大家分享下有关MySQL在数据安全的话题,怎么通过一些配置来保证数据安全以及保证数据的存储落地是安全的. 我是在2014年加入陌陌,2015年加入去哪儿网,做MySQL的运维,包括自动化的开发. 接 ...
- java系统的优化
1.tomcat.jboss.jetty的jvm内存,增大 2.数据库的优化,如MySQL的innodb_buffer_pool_size等参数,增大
- Unity3D Instantiate慢的问题
1.NGUI直接打开界面卡 2.角色放技能的时候卡 3.载入模型的时候卡 http://www.xuanyusong.com/archives/2925
- WebApi Owin SelfHost OAuth2 - 授权服务和资源服务分离方案
使用JWT 参考:http://www.cnblogs.com/grissom007/p/6294746.html
- Code Conventions for the JavaScript Programming Language
This is a set of coding conventions and rules for use in JavaScript programming. It is inspired by t ...
- IntelliJ IDEA + Tomcat 部署问题
首先要了解下 tomcat的 几种部署方式(大致分为静态部署和动态部署),可以百度,博客:http://qsfwy.iteye.com/blog/466461 IntelliJ IDEA 下部署项目的 ...
- Linux下./configure && make && make install 编译安装和卸载
正常的编译安装/卸载: 源码的安装一般由3个步骤组成:配置(configure).编译(make).安装(make install). configure文件是一个可执行的脚本文件,它有很多选项, ...