[AGC043B] 123 Triangle
个人思路:
首先,经过 \(1\) 轮就没有 \(3\) 了。
先考虑能否递推前 \(i\) 个数的答案,发现不行。
再考虑能否推出 \(i\) 个数的答案的计算公式,也发现不行。
然后就不会了。
正解:
首先,经过 \(1\) 轮就没有 \(3\) 了,只剩 \(0,1,2\),答案必然为三者之一。
我们发现,除非某行出现了全是 \(1\) 的情况,否则该行一定有 \(1\) 与 \(2\) 或 \(0\) 相邻,\(1\) 会留到下一行。这样 \(1\) 就会留到最后。如果出现了全是 \(1\) 的情况,下一步序列里全是 \(0\)。
如果第 \(2\) 行有 \(1\),答案要么是 \(0\) 要么是 \(1\),这个时候只需要判断答案奇偶性。\(|a-b|\) 和 \(a+b\) 在模 \(2\) 意义下是相等的。把操作的 \(|a-b|\) 视为 \(a+b\),我们可以计算第 \(2\) 行的第 \(i\) 个数在答案中计算了多少次。这个东西可以递推,但是复杂度会爆炸。我们发现这个数的递推式等价于组合数的递推式,因此次数为 \(C_{n-2}^{i-1}\)
答案即为 \(\sum\limits_{i=1}^{n-1} f_{2,i} \times C_{n-2}^{i-1} \mod 2\)。
如果第 \(2\) 行没有 \(1\),两个偶数相减不可能出现奇数,答案要么是 \(0\) 要么是 \(2\)。我们直接把所有数除以 2,这样也转为判断奇偶性的问题,答案乘上 \(2\) 就行了。
[AGC043B] 123 Triangle的更多相关文章
- [atAGC043B]123 Triangle
不妨先操作一轮,使得$0\le a_{i}\le 2$ 结论:若序列中存在1,则答案为0或1 考虑归纳,注意到若序列中存在1,除非所有元素均为1,否则操作一轮后必然仍存在1,那么根据归纳假设即成立,而 ...
- 二分--1043 - Triangle Partitioning
1043 - Triangle Partitioning PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit: ...
- 1043 - Triangle Partitioning(数学)
1043 - Triangle Partitioning PDF (English) Statistics Forum Time Limit: 0.5 second(s) Memory Limit ...
- Entity Framework 6 Recipes 2nd Edition(12-3)译 -> 数据库连接日志
12-3. 数据库连接日志 问题 你想为每次与数据库的连接和断开记录日志 解决方案 EF为DbContext的连接公开了一个StateChange 事件.我们需要处理这个事件, 为每次与数据库的连接和 ...
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
随机推荐
- python 搭建自启动FTP服务器,编译后exe后个人随时可用,非常方便
import win32apiimport win32conclass AutoRun: """ itemname:要添加的项值名称 , path:要添加的exe路径绝对 ...
- mysql生成随机数的函数
例:update [tablename] set [columnname] = FLOOR( 6546541 + RAND() * (987987989 - 6546541)) where ? FLO ...
- 编译报错Could NoT find Threads (missing: Threads FOUND)
解决方法1: 原来的命令行加上-lpthread 解决方法2: -DCMAKE_THREAD_LIBS_INIT=-lpthread
- 【SSO单点系列】(8):CAS4.0 之整合CMS
一.描术 CMS 是采用shiro来认证的: 过程 1.调用 login.do get方式 来打开登录页面 2.录入用户名密码后调用/login.do的post来提交 并且只能是post提交 Jar ...
- Gitbook编写JSON文件
title: Gitbook编写JSON文件 # 标题 date: 2020-10-31 16:34:30 updated: 2020-12-31 categories: 前端 tags: JSON ...
- shell_Day04
grep程序 Linux下有文本处理三剑客 -- grep sed awk grep:文本 行过滤工具 sed: 文本 行编辑器(流编辑器) awk:报告生成器(做文本输出格式化) grep 包含三个 ...
- C语言源文件如何编译为exe
先观看https://blog.csdn.net/u014772182/article/details/43348465来配置gcc环境随后在cmd中cd到目标文件夹gcc main.c -o ste ...
- ES6-moudle
一.基础认知 结合案例体验module: 前面模拟模块是用立即执行的匿名函数,需要把某些通过window暴露出去,所以还是不能消除全局变量 module模块系统需要服务器环境才能正常执行,在html文 ...
- 记录POI导入时单元格下拉框两种实现方式(excel数据有效性)
如果下拉选项字符少于225 使用方式1 public static HSSFSheet setHSSFValidation(HSSFSheet sheet, String[] textlist, in ...
- shell - scriptfifo
shell1: mkfifo xxfifo script -f xxfifo cmd cmd exit -----主动退出 shell2: cat xxfifo 可以看到shell1的所有操作. ...