SRM444DIV1 550分
大概意思是给定一个一定长宽的表,现在手中有两种卡片一种是2*2的“4”字卡片(16分),另一种是1*1的“1”字卡片(1分),卡片数不限,计算可以将其填入表中得到的最大分,图表中可能已有卡片存在。
*Problem Statement
NOTE: This problem statement contains images that may not display properly if viewed outside of the applet.
"4Blocks" is a two player cooperative game played on a special board. The board is a grid composed of 1x1 square cells. There are two different kinds of blocks: '1' blocks and '4' blocks. '1' blocks are 1x1, and '4' blocks are 2x2:
You must place blocks on the board so that their sides are aligned to the grid lines and no two blocks overlap. The final score is the sum of the values in each cell. '1' blocks are worth 1 point, and '4' blocks are worth 16 points because they cover 4 cells and each cell is worth 4 points.
Your friend has taken his turn and placed a number of '1' blocks on the board. The current configuration is given in the String[] grid. The j-th character of the i-th element of grid is '.' if the cell at row i, column j is empty, and '1' if your friend placed a '1' block in that cell. It is now your turn, and you can place any number of '1' or '4' blocks on the board, but you cannot remove any of the blocks that have already been placed. Return the maximum score that can be achieved. For example, the following images show one possible starting state, and the optimal placement of blocks from that state:
The final score would be 4*16 + 6*1 = 70.
Definition
Class: FourBlocks
Method: maxScore
Parameters: String[]
Returns: int
Method signature: int maxScore(String[] grid)
(be sure your method is public)
Constraints
- grid will contain between 1 and 10 elements, inclusive.
- Each element of grid will contain between 1 and 25 characters, inclusive.
- All elements of grid will contain the same number of characters.
- Each element of grid will contain only '.' or '1' (one).
Examples
0)
{".....1..1..",
"..1.....1.."}
Returns: 70
This is the example from the statement.
1)
{"...1.",
".....",
".1..1",
".....",
"1...."}
Returns: 73
2)
{"...1.",
".1...",
"..1.1",
"1...."}
Returns: 20
It is not possible to place any '4' bricks in this setup.
3)
{".....1...",
".....1...",
"111111111",
".....1...",
".....1..."}
Returns: 117
发现最做Topcoder有个老是习惯先浏览一下其他人的算法,大概心里有数。这道题刚开始看时确实有点吓到,列位大牛写的东西几乎看不懂,还用到了位运算,有的就用三维数组,真是云里雾里。
不过自己尝试一下发现不是那么回事,一气写下来就调了一个bug,算了一下复杂度照其他来说还是比较低的。
可见有时候还是应该相信自己多一点。算法如下:
相关推荐
python教程学习
tdac034.pdf
veclibm111111111111
nssm工具,进行2次解压后即可
视讯镜头优化,操作不走
【数据结构】的资源,包括书籍、在线课程和网站
北京大学-DeepSeek系列-提示词工程和落地场景.pdf.png
【财信国际经济研究院-2025研报】2025年2月CPI和PPI数据点评:通胀低于预期,内需亟待提振.pdf
【毕业设计】java-springboot+vue精品在线试题库系统源码(完整前后端+mysql+说明文档+LunW).zip
python安装-25.求 a 的 b 次方——有点不好意思哈.py
代码实现了自适应IMM(交互式多模型)算法,专注于对目标状态进行估计,并结合了匀速(CV)和匀加速(CA)运动模型。它使用自适应观测噪声估计和扩展卡尔曼滤波器(EKF)作为滤波主体,并在最后提供误差统计特性输出。
中产品工业物联网联网的基础功能,是企业开启数字化转型的入门之选。它能帮助企业快速搭建起基础的设备数据采集与监控体系,以较低成本实
北京大学DeepSeek系列-DeepSeek与AIGC应用.pdf.png
【毕业设计-java】springboot-vue基于多维分类的知识管理系统实现源码(完整前后端+mysql+说明文档+LunW).zip
## 一、数据介绍 本数据参考C刊《管理评论》佟岩(2024)老师的做法,使用各年度省级政府工作报告中“减碳”关键词的词频总数来测度地方政府对“减碳”的重视程度,“减碳”关键词包括二氧化碳、低碳、减排、节能、能耗、环境保护(环保)、生态、绿色。 本数据包含:原始数据、参考文献、代码do文件、最终结果。 ## 二、参考文献: 佟岩,李鑫,徐国铨.企业集团碳减排压力与债务分布-来自高耗能上市公司的经验证据[J].管理评论,2024,36(02):210-221.DOI:10.14120/j.cnki.cn11-5057/f.2024.02.014 ## 三、相关数据:城市、城市编码、年份、减碳重视程度词频。
python教程学习
jfinal-undertow 用于开发、部署由 jfinal 开发的 web 项目
python学习一些项目和资源
锐捷设备命令最全大合集
uniapp-machine-learning-from-scratch-05.rar