poj 2081 Recaman's Sequence (dp)】的更多相关文章

Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22566   Accepted: 9697 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence,…
Recaman's Sequence Time Limit: 3000ms Memory Limit: 60000KB This problem will be judged on PKU. Original ID: 208164-bit integer IO format: %lld      Java class name: Main   The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the…
                                                                                                      Recaman's Sequence Time Limit: 3000MS   Memory Limit: 60000K Total Submissions: 22363   Accepted: 9605 Description The Recaman's sequence is defined…
開始还以为暴力做不出来,须要找规律,找了半天找不出来.原来直接暴力.. 代码例如以下: #include<stdio.h> int a[1000050]; int b[100000000]={0}; int main() { int i,k; a[0]=0; for(i=1;i<=500000;i++) { a[i]=a[i-1]-i; if(a[i-1]-i>0&&!b[a[i-1]-i]) a[i]=a[i-1]-i; else a[i]=a[i-1]+i; b…
[简要题意]:这个主题是很短的叙述性说明.挺easy. 不重复. [分析]:只需要加一个判断这个数是否可以是一个数组,这个数组的范围. // 3388K 0Ms #include<iostream> using namespace std; #define Max 500001 int a[Max]; bool b[10000000] = {false}; // b的数据范围是能够试出来的- void init() { a[0] = 0; b[0] = true; for(int m = 1;…
[POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted: 2222 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all tea…
Recaman's Sequence Time Limit: 3000MS Memory Limit: 60000K Total Submissions: 22392 Accepted: 9614 Description The Recaman's sequence is defined by a0 = 0 ; for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence, othe…
poj  3311(状态压缩DP) 题意:一个人送披萨从原点出发,每次不超过10个地方,每个地方可以重复走,给出这些地方之间的时间,求送完披萨回到原点的最小时间. 解析:类似TSP问题,但是每个点可以重复走,先用floyd预处理每个点两两之间的最短距离,然后用状态压缩DP求出走完所有点后回到原点的最短距离,用一个二进制数表示城市是否走过. 状态表示:dp[i][j]表示到达j点状态为i的最短距离 状态转移方程:dp[i][j]=min(dp[i][j],dp[j'][k]+dis[k][j]),…
poj  1185(状态压缩DP) 题意:在一个N*M的矩阵中,‘H'表示不能放大炮,’P'表示可以放大炮,大炮能攻击到沿横向左右各两格,沿纵向上下各两格,现在要放尽可能多的大炮使得,大炮之间不能相互攻击. 解析:可以发现,对于每一行放大炮的状态,只与它上面一行和上上一行的状态有关,每一行用状态压缩的表示方法,0表示不 放大炮,1表示放大炮,同样的,先要满足硬件条件,即有的地方不能放大炮,然后就是每一行中不能有两个1的距离小于 2(保证横着不互相攻击),这些要预先处理一下.然后就是状态表示和转移…
poj  3254(状态压缩DP) 题意:一个矩阵里有很多格子,每个格子有两种状态,可以放牧和不可以放牧,可以放牧用1表示,否则用0表示,在这块牧场放牛,要求两个相邻的方格不能同时放牛,即牛与牛不能相邻.问有多少种放牛方案(一头牛都不放也是一种方案) 解析:根据题意,把每一行的状态用二进制的数表示,0代表不在这块放牛,1表示在这一块放牛.首先很容易看到,每一行的状态要符合牧场的硬件条件,即牛必须放在能放牧的方格上.这样就能排除一些状态.另外,牛与牛之间不能相邻,这样就要求每一行中不能存在两个相邻…
/*poj 2324 Anniversary party(树形DP) ---用dp[i][1]表示以i为根的子树节点i要去的最大欢乐值,用dp[i][0]表示以i为根节点的子树i不去时的最大欢乐值, ---于是当i去时,i的所有儿子都不能去:dp[i][1]=sum(dp[j][0])+a[i],其中j是i的儿子节点. ---当i不去时,i的儿子可去也可不去:dp[i][0]=sum(max(dp[j][0],dp[j][1])),j是i的儿子节点 ---边界条件:当i时叶子节点时,dp[i][…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27793   Accepted: 7885   Special Judge Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a re…
Cut the Sequence \(solution:\) 这道题出的真的很好,奈何数据水啊! 这道题当时看得一脸懵逼,说二分也不像二分,说贪心也不像贪心,说搜索吧这题数据范围怎么这么大?而且这题看起来也实在不好DP,当时是真的满头雾水.只能说是各个都尝试一下.最后还是选了DP来做第一步突破,因为这道题可以用最优子结构来推出最优答案,也符合常规DP套路即设 \(F[i][j]\) 表示将前面 $ i $ 个数分成 $ j $ 份,但是这一道题没有说具体的份数,而且数据范围很大,所以我们直接设…
题目链接 很早 很早之前就看过的一题,今天终于A了.状态转移,还算好想,输出路径有些麻烦,搞了一个标记数组的,感觉不大对,一直wa,看到别人有写直接输出的..二了,直接输出就过了.. #include <cstdio> #include <cstring> #include <iostream> using namespace std; ][]; ]; ]; ]; int dfs(int L,int R) { int i,minz; if(dp[L][R]) retur…
题意: 给定含有n个元素的数列a,要求将其划分为若干个连续子序列,使得每个序列的元素之和小于等于m,问最小化所有序列中的最大元素之和为多少?(n<=105.例:n=8, m=17,8个数分别为2 2 2 | 8 1 8 |1 2,答案为12.) 思路: 想明白一个队列+一个set就能完美解决这个问题? 首先DP的转移式子是:dp[i]=min( dp[j] +max[j+1, i]  ),且sum[i]-sum[j]<=m,j为枚举的断开处.暴力寻找一个合适的j的复杂度为O(n2).那么问题就…
DP + 单调队列优化 + 平衡树 好题 Description Given an integer sequence { an } of length N, you are to cut the sequence into several parts every one of which is a consecutive subsequence of the original sequence. Every part must satisfy that the sum of the intege…
题目链接:http://poj.org/problem?id=1180 Description There is a sequence of N jobs to be processed on one machine. The jobs are numbered from 1 to N, so that the sequence is 1,2,..., N. The sequence of jobs must be partitioned into one or more batches, wh…
Censored! Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 6956   Accepted: 1887 Description The alphabet of Freeland consists of exactly N letters. Each sentence of Freeland language (also known as Freish) consists of exactly M letters w…
题目链接:http://poj.org/problem?id=1651 Description The multiplication puzzle is played with a row of cards, each containing a single positive integer. During the move player takes one card out of the row and scores the number of points equal to the prod…
http://poj.org/problem?id=1661 对板按高度排序后. dp[i][0]表示现在站在第i块板上,向左跑了,的状态,记录下时间和其他信息. O(n^2)LIS: 唯一的麻烦就是,如果由第i块板---->第j块板,除了高度差会摔死之后,还可能会中间隔着一些板,使得它是去不了第j块的 所以用个vis标记下,如果i--->j中,vis[i]已经是true,表示第i块板已经被其他板截住了.判断一下就好. #include <cstdio> #include <…
题目链接: POJ 3345 Bribing FIPA 题意: 一个国家要参加一个国际组织,  需要n个国家投票,  n个国家中有控制和被控制的关系, 形成了一颗树. 比如: 国家C被国家B控制, 国家B被国家A控制, 那么B , C 会跟着A投同一家国家. 而要有些国家给它投票, 就得用若干钻石去贿赂那些国家. 最后问, 要到至少有m个国家投它的票, 最少需要多少钻石. 分析: 对于每一个结点只有两种状态, 选与不选, 所以dp方程里加上一维即可. dp[i][j][k], 表示在i的子结点中…
http://poj.org/problem?id=1260 Pearls Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 8474   Accepted: 4236 Description In Pearlania everybody is fond of pearls. One company, called The Royal Pearl, produces a lot of jewelry with pearls…
http://poj.org/problem?id=2192 Zipper Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17585   Accepted: 6253 Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the…
Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6033   Accepted: 3220 Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular…
题目链接:http://poj.org/problem?id=1947 一共有n个节点,要求减去最少的边,行号剩下p个节点.问你去掉的最少边数. dp[u][j]表示u为子树根,且得到j个节点最少减去的边数. 考虑两种情况,去掉孩子节点v与去不掉. (1)去掉孩子节点:dp[u][j] = dp[u][j] + 1 (2)不去掉孩子节点:dp[u][j] = min(dp[u][j - k] + dp[v][k]) 综上就是dp[u][j] = min(dp[u][j] + 1, min(dp[…
题目链接:http://poj.org/problem?id=2342 有n个人,每个人有活跃值.下面n-1行u和v表示u的上司是v,有直接上司和下属的关系不能同时参加party,问你party最大的活跃值是多少. 也就是说一棵树中,选择的点不能是相邻的点,且要使活跃值最大. 简单的树形dp,任意选一个点开始遍历,从叶子节点开始回溯. dp[i][0]表示不选i节点最大的活跃度,则dp[i][1]表示选i节点最大的活跃度. i与j相连,dp[i][0] += max(dp[j][0], dp[j…
题目链接:http://poj.org/problem?id=3616 有头牛产奶n小时(n<=1000000),但必须在m个时间段内取奶,给定每个时间段的起始时间和结束时间以及取奶质量 且两次取奶之间须间隔r-1个小时,求最大取奶质量 也就是说r = 2时 3分结束取奶,至少在5分才能取. 按照时间排序,dp[i]表示i时段的最大产奶量 //#pragma comment(linker, "/STACK:102400000, 102400000") #include <a…
E. LIS of Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/486/problem/E Description The next "Data Structures and Algorithms" lesson will be about Longest Increasing Subsequence (LIS for short) of a sequence.…
题目链接:http://poj.org/problem?id=2342 题意:一家公司有1 <= N <= 6 000个职工,现要组织一些职工参加晚会,要求每个职工和其顶头上司不能同时参加晚会,并且每个职工有一个enjoy值,问选取的职工的最大enjoy总和为多少? 输入N个职工各种的enjoy值,和L K表示K是L的顶头上司: 思路:建图之后DFS,dp[u][1] :u去时,以u为根的子树最大enjoy值,dp[u][0]:u不去时,以u为子树的enjoy值: 则dp[u][1] += d…
题目链接:http://poj.org/problem?id=3017 这题的DP方程是容易想到的,f[i]=Min{ f[j]+Max(num[j+1],num[j+2],......,num[i]) | 满足m的下界<j<=i },复杂度O(n^2),妥妥的TLE.其实很多都决策都是没有必要的,只要保存在满足m的区间内,num值单调递减的的那些决策.如果遍历的话,一个下降的序列会退化到O(n^2),于是用堆来优化...堆优化这里,纠结了很久T_T,,,网上很多代码都是直接用set来处理,但…