C. Divide by Three DP】的更多相关文章

Divide Chocolate Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1465    Accepted Submission(s): 682 Problem Description It is well known that claire likes dessert very much, especially chocolat…
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…
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://acm.hdu.edu.cn/showproblem.php?pid=4301 题意: 有一块n*2大小的巧克力,现在某人要将这巧克力分成k个部分,每个部分大小随意,问有多少种分法. 思路: dp [ i ] [ j ] [ 0/1 ]表示到第 i 列时分成 j 块的方案数,0/1表示第 i 列的两格巧克力是否相连. 这样的话,分析到第 i 块时的情况如下: ①块数不变 dp[i][j][] = dp[i][j][] + dp[i-][j][]* dp[i][j][] = dp[i…
http://codeforces.com/contest/792/problem/C 这题奇葩题我居然用dp过了. 如果要模拟的话,可以用一个栈保存,保存每一个%3 = 2的pos,%3 = 1的pos,注意到题目是最多删除2个数,就能使得整个数%3=0了,如果要删除前导0的话就另外算. 那么贪心从栈顶删除,也就是先删除后面的数就行.然后需要删除2,又分两种情况,删除两个1和删除一个2..等等,一路模拟. 比赛的时候没想到这样,也觉得很复杂,于是就dp了,虽然TLE了,但是加了一个剪枝就过了,…
A. Array Factory 将下标按前缀和排序,然后双指针,维护最大的右边界即可. #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; const int N=200010; int n,i,j,anslen,ansl,ansr,mr,q[N]; ll a[N],lim; inline bool cmp(int x,int y){return a[x]<a[y];…
题目分析: 这种乱七八糟的题目一看就是点分治,答案有单调性,所以还可以二分答案. 我们每次二分的时候考虑答案会不会大于等于某个值,注意到系数$k$是无意义的,因为我们可以通过转化使得$k=0$. 合并的过程相当于很多个向量,加起来后看斜率. 注意单个向量也要判定. 由于有了二分的答案$Ans$.判定变得简单多了,推一下. 令$(A,C)$是从一个点到重心的一个向量,$(B,D)$是从另一个点到重心的向量.其中$A$和$B$是重心到该点的路径权值和,$C$和$D$是经过的边数. $-k \leq…
题目链接 https://loj.ac/problem/6502 题解 中间一档部分分提示我们将所有的 \(w_i\) 排序. 考虑如果我们能构造出这样一个 \(w_i\) 的序列,使得该序列满足:对于任意的 \(i(1 \leq i \leq n)\),所有的 \(j(1 \leq j < i)\) 都满足 \(w_i + w_j \geq m\) 或者所有的 \(j(1 \leq j < i)\) 都满足 \(w_i + w_j < m\),那么我们就可以使用动态规划求解. 具体地,…
直接暴力dp就行……f(i,j)表示前i天集齐j种类的可能性.不超过10000天就能满足要求. #include<cstdio> using namespace std; #define EPS 1e-10 int K,q,p; double f[10010][1010]; int main() { // freopen("d.in","r",stdin); scanf("%d%d",&K,&q); f[0][0]=1…
Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4478   Accepted: 1292 Description Yixght is a manager of the company called SzqNetwork(SN). Now she's very worried because she has just received a bad news which denotes that DxtNet…
POJ 3744 Scout YYF I 这就是一个乱搞题,暴力发现TLE了,然后看了看discuss里说可以矩阵加速,想了一会才想明白怎么用矩阵,分着算的啊.先算f[num[i]-1]之类的,代码太长了,还是找找规律吧.. #include <cstdio> #include <cstring> #include <iostream> #include <map> #include <algorithm> #include <vector…
专题链接 第一题--poj3744 Scout YYF I  链接 (简单题) 算是递推题 如果直接推的话 会TLE 会发现 在两个长距离陷阱中间 很长一部分都是重复的 我用 a表示到达i-2步的概率 b表示到达i-1步的概率 c表示到达i步的概率 如果数很大的话 中间肯定会有重复的a,b,c 直接将i挪到最近的陷阱前一位 i = a[o]-1,大大节省时间. #include <iostream> #include<cstdio> #include<cstring>…
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = 6. More practice:…
Description Your task is to divide a number of persons into two teams, in such a way, that: everyone belongs to one of the teams; every team has at least one member; every person in the team knows every other person in his team; teams are as close in…
链接:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25585 Current Server Time: 2013-08-27 20:42:26 Robots on a grid Time Limit: 3000ms Memory Limit: 65536KB   64-bit integer IO format: %lld      Java class name: Main Prev Submit Status Statistics Disc…
题目链接: D. Kindergarten time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated e…
Group Projects Description There are n students in a class working on group projects. The students will divide into groups (some students may be in groups alone), work on their independent pieces, and then discuss the results together. It takes the i…
题目链接: http://acm.hust.edu.cn/vjudge/problem/116998 Cent Savings Time Limit: 3000MS 问题描述 To host a regional contest like NWERC a lot of preparation is necessary: organizing rooms and computers, making a good problem set, inviting contestants, designin…
一道比较不错的BFS+DP题目 题意很简单,就是问一个刚好包含m(m<=10)个不同数字的n的最小倍数. 很明显如果直接枚举每一位是什么这样的话显然复杂度是没有上限的,所以需要找到一个状态表示方法: 令F[i][j] 表示已经用了 i (二进制压位表示)用了 i 这些数字,且余数j为的状态,枚举时直接枚举当前位,那么答案明显就是F[m][0] 我这里将状态i, j存在了一维空间里,即 i * 1000 + j表示,实际上用一个结构体存队列里的点,用二维数组标记状态也是可行的. #include…
D. Kindergarten Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/484/D Description In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child wi…
题意:1-n个位置中,每个位置填一个数,问至少有l个数是相同的概率. 可以转化求最多有l-1个数是相同的. dp[i][j]表示前i个位置填充j个位置的方案数,并且要满足上面的条件. 则: dp[i][j]=∑dp[i-1][j-k]*c[m-j+k][k]; 也就是看第i个数,可以不填,填一个位置,两个位置······这样累加过来. 代码如下: import java.math.*; import java.util.*; public class Main { public static v…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3380 题意:有m种不同的元素,每种元素都有n种不同的相位,现在假设有每种元素各一个,其相位是等概率随机的.如果几个元素的相位相同,那么帕琪就可以把它们组合发动一个符卡(Spell Card).现在问帕琪能够发动等级不低于l,即包含l个相同相位的不同元素的附卡的概率. 首先所有的总数是n^m,然后只要求满足情况的数目了,对于 l >m/2我们可以直接用组合数来求的…
Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scribers. The scriber had been given a book and after several months he finished its copy. One of…
Problem 1608 - Calculation Time Limit: 500MS   Memory Limit: 65536KB    Total Submit: 311  Accepted: 82  Special Judge: No Description Today, Alice got her math homework again! She had n integers, and she needed to divide them into several piles or o…
Dividing coins It's commonly known that the Dutch have invented copper-wire. Two Dutch men were fighting over a nickel, which was made of copper. They were both so eager to get it and the fighting was so fierce, they stretched the coin to great lengt…
Copying Books Time Limit: 3000MS Memory Limit: 10000K Total Submissions: 7109 Accepted: 2221 Description Before the invention of book-printing, it was very hard to make a copy of a book. All the contents had to be re-written by hand by so called scri…
Oh My Holy FFF Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 606    Accepted Submission(s): 141 Problem Description N soldiers from the famous "*FFF* army" is standing in a line, from le…
Dividing Time Limit: 1000MS Memory Limit: 10000K Description Marsha and Bill own a collection of marbles. They want to split the collection among themselves so that both receive an equal share of the marbles. This would be easy if all the marbles had…
Maximum Subarray Find the contiguous subarray within an array (containing at least one number) which has the largest sum. For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] has the largest sum = 6. click to show m…
F. Group Projects time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output There are n students in a class working on group projects. The students will divide into groups (some students may be in g…