A 模拟

B 发现对于每个连通块,只有为完全图才成立,然后就dfs

C 构造  想了20分钟才会,一开始想偏了,以为要利用相邻NO YES的关系再枚举,其实不难。。

考虑对于顺序枚举每一个NO/YES,与前一个需要用的的字符串有k-1个交集,只多了一个string

于是只要保证k-1个string不同,只通过当前的string来影响答案,

若YES,开一个新的串; NO,则和第一个串一样,以此让这个相同串在下一次枚举中消失。。

//怎么想到?  其实NO可能有多个相同名字,关系就很乱了,我们希望只有1个名字重复,且只重复1次,然后再接着考虑

D 考虑如何求树上所有点对的距离和 : 只需求出每条边对答案的贡献累加即可。

原问题转化为求所有  =L/k + f(L,k)/k  f(L,k):L最少加几才能是k的倍数

第一部分可以直接O(n)求,f(L,k)可以通过L%k的值得出,问题转化为求所有L%k的值为0..k-1分别有几组。

待统计的二点形成链,链有2种,一种是有某个点为LCA,否则是另一种。

对于情况1,直接dp O(nk)

情况2,dp记录前缀和,将孩子信息合并,O(n*k^2)

这数数题还是挺好的

Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)的更多相关文章

  1. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 菜鸡只会ABC!

    Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) 全场题解 菜鸡只会A+B+C,呈上题解: A. Bear and ...

  2. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C. Bear and Different Names 贪心

    C. Bear and Different Names 题目连接: http://codeforces.com/contest/791/problem/C Description In the arm ...

  3. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) B - Bear and Friendship Condition 水题

    B. Bear and Friendship Condition 题目连接: http://codeforces.com/contest/791/problem/B Description Bear ...

  4. 【树形dp】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) B. Bear and Tree Jumps

    我们要统计的答案是sigma([L/K]),L为路径的长度,中括号表示上取整. [L/K]化简一下就是(L+f(L,K))/K,f(L,K)表示长度为L的路径要想达到K的整数倍,还要加上多少. 于是, ...

  5. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1)A B C 水 并查集 思路

    A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes input stand ...

  6. 【构造】Codeforces Round #405 (rated, Div. 1, based on VK Cup 2017 Round 1) A. Bear and Different Names

    如果某个位置i是Y,直接直到i+m-1为止填上新的数字. 如果是N,直接把a[i+m-1]填和a[i]相同即可,这样不影响其他段的答案. 当然如果前面没有过Y的话,都填上0就行了. #include& ...

  7. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) E

    Description Bear Limak prepares problems for a programming competition. Of course, it would be unpro ...

  8. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) D

    Description A tree is an undirected connected graph without cycles. The distance between two vertice ...

  9. Codeforces Round #405 (rated, Div. 2, based on VK Cup 2017 Round 1) C

    Description In the army, it isn't easy to form a group of soldiers that will be effective on the bat ...

随机推荐

  1. 创建Springmvc项目时,特殊拦截器失效情况的原因及解决办法

    最近开发一个新项目时,搭建springmvc框架时,遇到一个拦截器失效的情况困扰了两天.现在解决,特此记录一下. 拦截器不生效的情况描述: 设置登录拦截的时候,首先登录接口肯定是不用拦截的.所以需要在 ...

  2. Android开发笔记——ListView模块、缓存及性能

    ListView是Android开发中最常用的组件之一.本文将重点说明如何正确使用ListView,以及使用过程中可能遇到的问题. ListView开发模块 图片缓存 可能遇到的问题 一.ListVi ...

  3. Introduction to Locking in SQL Server

    Locking is a major part of every RDBMS and is important to know about. It is a database functionalit ...

  4. 基于MapReduce的(用户、物品、内容)的协同过滤推荐算法

    1.基于用户的协同过滤推荐算法 利用相似度矩阵*评分矩阵得到推荐列表 已经推荐过的置零 2.基于物品的协同过滤推荐算法 3.基于内容的推荐 算法思想:给用户推荐和他们之前喜欢的物品在内容上相似的物品 ...

  5. Qt 利用XML文档,写一个程序集合 二

    接上一篇文章https://www.cnblogs.com/DreamDog/p/9213915.html XML文档的读写 一个根节点,下面每一个子节点代表一个子程序,内容为子程序名字,图标路径,e ...

  6. Docker--从安装到搭建环境

    docker 1. ubuntu下安装docker 安装docker有两种方法: 一种是用官方的bash脚本一键安装. 直接一条命令就解决了: $ curl -sSL https://get.dock ...

  7. jmeter执行顺序及作用域规则

    1.执行顺序 配置元件 前置处理器 定时器 采样器 后置处理器 断言 监听器 备注: 服务器响应为空的话后三个不执行 作用域内存在采样器时定时器.断言.前置/后置处理器才执行 逻辑控制器和采样器按照在 ...

  8. sql 命令使用简单记录

    半个月前就想记下用过的SQL命令的!!!     主题: 按时间查询: https://blog.csdn.net/hejpyes/article/details/41863349   左关联: se ...

  9. Unity中StopCoroutine不起作用怎么办

    1,只有StartCoroutine使用一个字符串方法名时才能用StopCoroutine(string CoroutineName)停用. 2, public Coroutine coroutine ...

  10. [转载] Centos7的安装、Docker1.12.3的安装,以及Docker Swarm集群的简单实例

    1.环境准备 ​ 本文中的案例会有四台机器,他们的Host和IP地址如下 c1 -> 10.0.0.31 c2 -> 10.0.0.32 c3 -> 10.0.0.33 c4 -&g ...