hdoj--2151--Worm(dp)】的更多相关文章

Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2584    Accepted Submission(s): 1667 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵. 突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过…
Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2637    Accepted Submission(s): 1707 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵. 突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过…
Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3395    Accepted Submission(s): 2188 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵. 突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过…
Worm Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3895 Accepted Submission(s): 2518 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有N棵. 突然Lele发现在左起第P棵树上(从1开始计数)有一条毛毛虫.为了看到毛毛虫变蝴蝶的过程,Lel…
主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cstdio> 3: #include <cstring> 4: using namespace std; 5:   6: double dp[35][35]; 7: double p[1005][35]; 8: int main() 9: { 10: // freopen("1.tx…
Palindrome subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65535 K (Java/Others)Total Submission(s): 1977    Accepted Submission(s): 822 Problem Description In mathematics, a subsequence is a sequence that can be derived fr…
代码: #include<iostream>   #include<cmath>   using namespace std;  int a[1005], dp[1005];  int main()  {      int n,sum,i,j;      while( scanf("%d",&n)&&n){             for( i=0; i<n; i++){                  scanf("%…
刚看题...觉得这不是棵树...可能有回路...仔细一想..这还真是棵树(森林)...这是由于每个城堡所需要提前击破的城堡至多一个..对于一个城堡.其所需提前击破的城堡作为其父亲构图.... dp[k][i]代表以k为跟的子树击破i个城堡所能获得的最大收益...泛化背包问题... Program: #include<iostream> #include<stack> #include<queue> #include<stdio.h> #include<…
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2069 题意 有面值1,5,10,25,50的硬币数枚,对于输入的面值n,输出可凑成面值n(且限制总硬笔数小于等于100枚)的方案数.特别的,n=0时方案数=1. 其中,输入n<=250. 思路 DP. 状态 ways[j][i] 表示面值等于j且硬币枚数等于i时的方案数. 初始化时,只需将ways[0][0]=1即可,其他为0: 外层先遍历硬币面值种类,这层遍历的具体顺序不重要,即保证有不重复累加同…
有 T(1<T<=1000) 支队伍和 M(0<M<=30) 个题目,已知每支队伍 i 解决每道题目 j 的的概率 p[i][j],现在问:每支队伍至少解决一道题,且解题最多的队伍的题目数量不少于 N(0<N<=M) 的概率是多少? p[i][j]表示第i个队伍做对第j题的概率.dp[i][j][k]表示第i个队伍在前j题中做对了k道的概率.dp[i][j][k] = dp[i][j-1][k-1]*(p[i][j])+dp[i][j-1][k]*(1-p[i][j])…
Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5750   Accepted: 2510 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp…
DP具体解释见: http://blog.csdn.net/liguan1/article/details/10468139 Derangement Time Limit: 7000/7000 MS (Java/Others)    Memory Limit: 65535/102400 K (Java/Others) Total Submission(s): 846    Accepted Submission(s): 256 Problem Description A derangement…
http://acm.hdu.edu.cn/showproblem.php?pid=2151 Worm Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3403    Accepted Submission(s): 2194 Problem Description 自从见识了平安夜苹果的涨价后,Lele就在他家门口水平种了一排苹果树,共有…
题意: 给一个n, 第二行给n堆的价值v[i], 第三行给a[i].  a[i]表示把i堆合在一起需要的花费. 求把n堆变成类似回文的 需要的最小花费. 思路: ①记忆化搜索 比较好理解... dp[l][r] 记录l到r的最小花费 枚举对称轴 维护每次l到r之间对称 dp[l][r]=min(dp[l][r], a[cur-l]+a[r-i]+dfs(cur+1, i-1)); l左边和r右边的合并 #include <cstdio> #include <cstdlib> #in…
题目传送门 /* 找规律/数位DP:我做的时候差一点做出来了,只是不知道最后的 is_one () http://www.cnblogs.com/crazyapple/p/3315436.html 数位DP:http://blog.csdn.net/libin56842/article/details/11580497 */ #include <cstdio> #include <iostream> #include <algorithm> #include <c…
题目传送门 /* 递推DP: 如果a, b, c是等差数列,且b, c, d是等差数列,那么a, b, c, d是等差数列,等比数列同理 判断ai-2, ai-1, ai是否是等差(比)数列,能在O(n)时间求出最长的长度 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; typedef long long ll…
题目传送门 /* 题意:给一个区间,问任意两个数的素数因子的GCD最大 数学+dp:预处理出f[i],发现f[i] <= 7,那么用dp[i][j] 记录前i个f[]个数为j的数有几个, dp[r][j] - dp[l-1][j]表示区间内j的个数,情况不多,分类讨论一下 */ #include <cstdio> #include <algorithm> #include <cstring> #include <vector> #include <…
poj double 就得交c++,我交G++错了一次 题目:http://poj.org/problem?id=2151 题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 问 每队至少解出一题且冠军队至少解出N道题的概率. 每队均至少做一题的概率P1 减去 每队做题数均在1到N-1之间的概率P2 设dp[i][j][k]表示第i个队在前j道题中解出k道的概率 则: dp[i][j][k]=dp[i][j-1][k-1]*p[j][k]+dp[i][j-1][k]*(1-p…
// l表示从l[i]到i连续大于a[i]的最远左区间.r表示从i到r[i]连续大于a[i]的最远又区间 DP 找出 a[i] 的最远左区间和最远右区间与自己连着的比自己大的数的长度 , 然后用这个长度乘以 a[i], 乘积最大的那个就是答案 hdoj 1506 #include<stdio.h> #include<string.h> #include<algorithm> using namespace std; #define N 100000+10 #define…
题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit: 65536K 问题描述 Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contes…
HDOJ(HDU).2844 Coins (DP 多重背包+二进制优化) 题意分析 先把每种硬币按照二进制拆分好,然后做01背包即可.需要注意的是本题只需要求解可以凑出几种金钱的价格,而不需要输出种数.因此用0表示不可以,1表示可以.最后对dp数组扫描一遍即可. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 100…
HDOJ(HDU).1059 Dividing(DP 多重背包+二进制优化) 题意分析 给出一系列的石头的数量,然后问石头能否被平分成为价值相等的2份.首先可以确定的是如果石头的价值总和为奇数的话,那么肯定不能被平分.若为偶数,则对valuesum/2为背包容量,全体石头为商品做完全背包.把完全背包进行二进制优化后,转为01背包即可. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #inclu…
HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化) 题意分析 首先C表示测试数据的组数,然后给出经费的金额和大米的种类.接着是每袋大米的价格,重量和袋数. 每种大米的数量是有限的,应该能看出是多重背包的问题.关键是多重背包的处理方法.对多重背包采用二进制优化的方法.设同种大米的数量为n,每袋的价格为v,那么把同一种大米分别拆成1,2,4,8,16--(直到不够2^n时,剩下的单独分成一组),拆分的价格也分别对应是v,2v,4v,8v…
HDOJ(HDU).2159 FATE (DP 带个数限制的完全背包) 题意分析 与普通的完全背包大同小异,区别就在于多了一个个数限制,那么在普通的完全背包的基础上,增加一维,表示个数.同时for循环多写一层即可. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 105 using namespace std; int dp[…
HDOJ(HDU).4508 湫湫系列故事――减肥记I (DP 完全背包) 题意分析 裸完全背包 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 100005 #define nn 105 using namespace std; int dp[nmax]; struct item{ int hap; int kal…
HDOJ(HDU).1284 钱币兑换问题 (DP 完全背包) 题意分析 裸的完全背包问题 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 33000 #define ll long long using namespace std; ll dp[nmax]; int coin[3]={1,2,3}; int mai…
HDOJ(HDU).1114 Piggy-Bank (DP 完全背包) 题意分析 裸的完全背包 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 100000 #define INF 0x3f3f3f3f using namespace std; int we[nmax],va[nmax],dp[nmax]; stru…
HDOJ(HDU).3466 Dividing coins ( DP 01背包 无后效性的理解) 题意分析 要先排序,在做01背包,否则不满足无后效性,为什么呢? 等我理解了再补上. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 505 #define nn 505*100 using namespace std;…
HDOJ(HDU).2546 饭卡(DP 01背包) 题意分析 首先要对钱数小于5的时候特别处理,直接输出0.若钱数大于5,所有菜按价格排序,背包容量为钱数-5,对除去价格最贵的所有菜做01背包.因为这时候还剩下5块钱,直接买最贵的那个菜,就可以保证剩下来的钱数是最小的. 代码总览 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nma…
HDOJ(HDU).2602 Bone Collector (DP 01背包) 题意分析 01背包的裸题 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #define nmax 1005 using namespace std; int v[nmax],w[nmax],dp[nmax]; int main() { //freopen("in…