【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 ...
随机推荐
- 在c++中实现反射的初步想法
最近在思考如何在c++中实现反射.事情的起因是这样的:我们服务器是用c++开发的,如果需要写一些测试用的GM指令的话,需要编写完GM代码后重新编译并且重启进程,工序繁琐且比较耗时.因此就有了想用脚本( ...
- 【小程序开发】上拉加载更多demo
wxml: <scroll-view class='swiper-scroll' scroll-y="{{true}}" bindscrolltolower="lo ...
- Python 模块进阶
import导入模块 1. import 搜索路径 import sys sys.path 例子: In [1]: import sys In [2]: sys.path Out[2]: ['', ' ...
- js权威指南---学习笔记02
1.JS只有函数作用域,没有块级作用域这个概念: 它有一个特性——声明提前:在同一个函数中不同位置声明的变量,都被提前在函数开始的时候,执行声明操作:在原先位置执行赋值操作: 2.声明的全局变量,相当 ...
- delphi TComponent类 2
来自:http://blog.csdn.net/lailai186/article/details/7442385 ------------------------------------------ ...
- AdvStringGrid 点击标题头 自动排序
- Eclipse 配置语言环境
一.打开https://www.eclipse.org/babel/downloads.php 选择一下版本的Bable(通天塔) 选择 解压 打开Eclipse 软件 选择Help->inst ...
- Codeforces 807C - Success Rate(二分枚举)
题目链接:http://codeforces.com/problemset/problem/807/C 题目大意:给你T组数据,每组有x,y,p,q四个数,x/y是你当前提交正确率,让你求出最少需要再 ...
- class getConstructor newinstance
public static void main(String[] args) throws Exception{ /**获取String对象指定的构造方法(通过方法的参数类型,传递 参数的 Class ...
- OBJECT_ID()的使用方法
数据库中每个对像都有一个唯一的ID值,用Object_name(id)可以根据ID值得到对像的名称,object_id(name)可以根据对像名称得到对象的ID object_id()只能返回用户创建 ...