2015-2016-petrozavodsk-winter-training-camp-spb-su-spb-au-contest F-Colored Path(状压DP)

该博客讨论了一种寻找权值不超过W的最短彩色路径的问题,路径从(1,1)到(n,n),每步只能向左或向下移动。路径的彩色度定义为不同颜色的数量。给出n×n棋盘的权重和颜色信息,要求找到彩色度最小的路径。博客提供了题意解析、题目分析以及使用状压DP的解决方案。" 111470201,9197393,云原生时代:如何选择正确的容器持久化存储方案?,"['云存储', '容器技术', '云原生架构', '数据持久化', 'Kubernetes平台']
摘要由CSDN通过智能技术生成

题面:

Colored Path

									Time limit: 1.5 seconds
								  Memory limit: 256 mebibytes

Problem Description

You have a board of size n × n. Each cell of the board has weight and color. Both weight and color are
positive integers. Rows and columns are enumerated from 1 to n. Let (i, j) be j-th cell of i-th row. In one
step you can move from cell (i, j) to cells (i, j + 1) and (i + 1, j).

Consider all paths from (1, 1) to (n, n) that obey the rule above. Obviously each such path contains
exactly 2n − 1 cells. Let’s define the weight of the path as the sum of the weights of the cells on the path.
Let’s define the colorness of the path as the number of different colors among the colors of the cells on
the path.

Given the weights and the colors of all cells, find the smallest colorness among all paths with weight no
more than W or report that there are no such paths.

Input

The first line contains three integers: n (1 ≤ n ≤ 400), k (1 ≤ k ≤ 10) which is the number of possible
colors, and W (1 ≤ W ≤ 1 0 9 10^9 109). Each of the next n lines contains n integers, j-th integer on i-th line is the
weight of the cell (i, j) (1 ≤ w i j w_{ij} wij 1 0 6 10^6 106). The last n lines contain n integers each, j-th integer on i-th line
is the color of the cell (i, j) (1 ≤ c i j c_{ij} cij ≤ k).

Output

On the first line output the minimal colorness of the path. On the second line output the path with
the minimal colorness in the format i 1 i_1 i1 j 1 j_1 j1 i 2 i_2 i2 j 2 j_2 j2 . . . i 2 n − 1 i_{2n−1} i2n1 j 2 n − 1 j_{2n−1}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值