Codeforces 816C/815A - Karen and Game】的更多相关文章

传送门:http://codeforces.com/contest/816/problem/C 本题是一个模拟问题. 有一个n×m的矩阵.最初,这个矩阵为零矩阵O.现有以下操作: a.行操作“row i”:对第i(1≤i≤n)行的所有元素加一: b.列操作“col j”:对第j(1≤j≤m)列的所有元素加一. 经过有限次操作,矩阵变为$G=(g_{i,j})_{m*n}$. 对于给定的矩阵G,试判断G是否可以由零矩阵O通过有限次的“行操作”和“列操作”生成?若可以,则求一个操作步数最小的方案:否…
[题目链接]:http://codeforces.com/contest/816/problem/C [题意] 给你一个n*m的矩阵; 一开始所有数字都是0; 每次操作,你能把某一行,或某一列的数字全部加上1; 问你到达目标矩阵最少需要进行多少次操作; [题解] 从目标矩阵开始减; 直接枚举每一列需要减多少次; 每一行需要减多少次即可; 但有技巧; 比如以下矩阵 1 1 1 1 1 1 1 1 1 1 1 1 应该一列一列地减比较快; 而 1 1 1 1 1 1 1 1 一行一行地删比较快; 所…
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and mcolumns. Each cell originally contains the number 0. One move consists of choosing one row or c…
Problem Description On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of…
Codeforces 815 C 考虑树型dp. \(dp[i][0/1][k]\)表示现在在第i个节点, 父亲节点有没有选用优惠, 这个子树中买k个节点所需要花的最小代价. 然后转移的时候枚举i的一个儿子u, 然后还要枚举在u的子树中选择了多少个节点l, 则\(dp[i][0/1][k+l]=dp[i][0/1][k]+dp[u][0/1][l]\). 还要注意转移顺序. 最后枚举最后一个\(dp[1][1][i]\leq limit\)的i就是答案.…
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or…
On the way home, Karen decided to stop by the supermarket to buy some groceries. She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods…
[题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k个以上的区间覆盖到; 则称之为特殊数字; 给你q个询问区间; 问你这q个区间里面 每个区间里面有多少个特殊数字; [题解] 对于覆盖的区间l,r add[l]++,sub[r+1]++, 然后顺序枚举 now+=add[i]; now-=sub[i]; 如果now>=k则i是一个特殊数字; 写个前缀和O…
[题目链接]:http://codeforces.com/contest/816/problem/A [题意] 让你一分钟一分钟地累加时间; 问多长时间以后是个回文串; [题解] reverse之后如果和原串相同,则为回文串; 模拟就好 [Number Of WA] 0 [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|…
题目链接:http://codeforces.com/contest/816/problem/E 题意:有n件商品,每件有价格ci,优惠券di,对于i>=2,使用di的条件为:xi的优惠券需要被使用,问初始金钱为b时 最多能买多少件商品? n<=5000,ci,di,b<=1e9 题解:显然是一道树形dp由于有两种情况就是当前点为根结点的时候选择打折还是不打折,如果选不打折之后的节点都不能打折. 不妨设dp[i][j][flag]表示i为根j为种类数,flag为状态表示选不选打折的最小花…