C. Divide by Three time limit per test: 1 second memory limit per test: 256 megabytes input: standard input output: standard output A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform…
题目链接:codeforces 792C. Divide by Three 今天队友翻了个大神的代码来问,我又想了遍这题,感觉很好,这代码除了有点长,思路还是清晰易懂,我就加点注释存一下...分类吧.删除一个数字模3为M的或删除两个模3为3-M的(还有一些要删零),具体看代码. #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<strin…
删除最少的数位和前缀0,使得剩下的数能被3整除 等价于各数位数字之和能被3整除. 当前数位和可能是 0, 1, 2(mod 3) 0: 直接处理 1: 删除一个a[i]%3 == 1 或者 两个a[i]%3 == 2 2: 同1 对于删完的数列,去掉前置0(只剩前置0就当作0) 若删啥都不满足,则判断原数列中有没有0,不然就输出-1 #include <bits/stdc++.h> using namespace std; ; char s[MAXN]; int a[MAXN], n; str…
链接:https://codeforces.com/contest/1288/problem/C C. Two Arrays 题意:给定一个数n和一个数m,让构建两个数组a和b满足条件,1.数组中所有元素的取值在1~n之间,a和b数组长度是m.2. a数组是单调不递减的,b数组是单调不递增 3. 任意的位置i,有ai<=bi 思路:可以组合数学做,也可以dp,以下为dp做法.首先如果把a.b两个数组合并成 a1,a2,a3,.......am,bm,bm-1,bm-2,bm-3.........…
[BZOJ 3625] [Codeforces 438E] 小朋友的二叉树 (DP+生成函数+多项式开根+多项式求逆) 题面 一棵二叉树的所有点的点权都是给定的集合中的一个数. 让你求出1到m中所有权值为i的二叉树的个数. 两棵树不同当且仅当树的形态不一样或者是树的某个点的点权不一样 分析 设\(c(i)\)表示数值i是否在集合中.\(f(i)\)表示权值为i的二叉树的个数.那么 \[f(n)=\sum_{i=1}^n c(i) \sum_{j=0}^{n-i} f(j)f(n-i-j)\] 其…
C. Divide by Three   A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The…
[题目链接]:http://codeforces.com/contest/792/problem/C [题意] 让你删掉最少的数字使得剩下的数字%3==0 [题解] 看代码..内置题解了现在. [完整代码] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long long #define rep1(i,a…
A positive integer number n is written on a blackboard. It consists of not more than 105 digits. You have to transform it into a beautiful number by erasing some of the digits, and you want to erase as few digits as possible. The number is called bea…
限制相邻元素,求合法序列数. /** 题目:On the Bench 链接:http://codeforces.com/problemset/problem/840/C 题意:求相邻的元素相乘不为平方数的方案数(这里求得是排列方案数,所以哪怕数相同,只要位置不同也算一种方案) 思路 : 每个数可以表示为 p1^a1 * p2^a2 * ..... 如果 两个数A,B相乘为平方数 则 a1%2 = a1' %2 , a2%2 = a2'%2 ..... 即 对应质因子的幂次 奇偶性相同 这样就可以…
题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高.  (1 ≤ a, b ≤ 100, 1 ≤ k ≤ 1000, 1 ≤ t ≤ 100) 1.我一开始的想法是DP出玩i轮得分是j的方案数.然后状态数最多有t*(2*k*t)那么多,最坏情况下会有2e7那么多的状态,转移必须是O(1)的. dp[i][j]=sum(dp[i-1][j-k....j+k]…