UVA 1619 Feel Good(DP)】的更多相关文章

Bill is developing a new mathematical theory for human emotions. His recent investigations are dedicated to studying how good or bad days influent people's memories about some period of life. A new idea Bill has recently developed assigns a non-negat…
uva 116 Unidirectional TSP Background Problems that require minimum paths through some domain appear in many different areas of computer science. For example, one of the constraints in VLSI routing problems is minimizing wire length. The Traveling Sa…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=39  Stacking Boxes  Background Some concepts in Mathematics and Computer Science are simple in one or two dimensions but become…
UVA 674  Coin Change  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/E 题目: Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount o…
In Frobnia, a far-away country, the verdicts in court trials are determined by a jury consisting of members of the general public. Every time a trial is set to begin, a jury has to be selected, which is done as follows. First, several people are draw…
题意:有一个老板和n个员工,除了老板每个员工都有唯一的上司,老板编号为0,员工们为1-n,工人(没有下属的员工),要交一份请愿书, 但是不能跨级,当一个不是工人的员工接受到直系下属不少于T%的签字时,自己也会签字,并交给上级,问你最少有多少工人签字,才能让老板收到请愿书. 析:题意比较简单,也好理解,很明显是一个动态规划的题目,d(u)表示u给上级要发信至少需要多少工人签字.假设u有k个结点,那么至少要 c = (kT-1)/100 + 1个工人,然后把每个结点排序,找出最少的工人即可,挺简单的…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=465&page=show_problem&problem=2399 最长的很简单,将串翻转过来后求两个串的lcs就是答案.. 主要是字典序那里... 还是开string来比较吧.. 注意最后输出方案时用前半段推出后半段.(因为可能lcs时会重合...) #include <cstdio> #include…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4513 题意: 有高为1, 2, 3,…, n的杆子各一根排成一行.从左边能看到L根,从右边能看到R根,求有多少种可能. 分析: 设d(i,j,k)表示让高度为1-i的杆子排成一行,从左边能看到j根,从右边能看到k根的方案数(设i≥2).按照从大到小的顺序安排各个杆子.假设已经安排完…
题意:有n个长度为1到n的柱子排列在一起,从左边看有l根从右边看有r根,问你所以排列中满足这种情况的方案数 题解:就是一个dp问题,关键是下标放什么,值代表什么 使用三维dp,dp[i][j][k]=l; i:从左边看的个数,j:从右边看的个数,k:后k根柱子,l:方案数 可以这样想:每次加上去的是比当前最小柱子小一的柱子,这样就可以发现,这根柱子放在k个位置都很好判断 即:dp[i][j][k]=dp[i-1][j][k-1](放在最左边)+dp[i][j-1][k-1](放在最右边)+dp[…
Ingenuous Cubrency 又是dp问题,我又想了2 30分钟,一点思路也没有,最后又是看的题解,哎,为什么我做dp的题这么烂啊! [题目链接]Ingenuous Cubrency [题目类型]dp &题意: 21种硬币,第i种的价值是i* i* i,给出一个数额,问有几种方法能组成这个数额. 比如这个数额是21,那么输出3,有3种方法: 1:21个1 2:1个8,13个1 3:2个8,5个1 &题解: 每次dp,要先想到dp的对象,这次就是要枚举输入的n. dp数组也要想到边界…
Suppose there are 5 types of coins: 50-cent, 25-cent, 10-cent, 5-cent, and 1-cent. We want to make changes with these coins for a given amount of money. For example, if we have 11 cents, then we can make changes with one 10-cent coin and one 1-cent c…
本文出自   http://blog.csdn.net/shuangde800 --------------------------------------------------------------------------------- 题意 给一个n*m大小的网格,有一些格子上面会有一个垃圾.机器人从左上角(1,1)出发,每次只能选择向右,或者向下走一步, 终点是(n, m).问最多可以捡多少个垃圾? 且捡最多垃圾有几种路径方案?注意路径方案指和有垃圾的格子有关. 思路 一开始没注意到方…
有一个n行m列的网格蛋糕,上面有一些樱桃.求使得每块蛋糕上都有一个樱桃的分割最小长度 思路:dp. #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<queue&…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1475 正反一次lis然后去min{左,右}*2-1即可 #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream&…
本文出自   http://blog.csdn.net/shuangde800 题目链接: 点击打开链接 题意 有n个仓库,让m个人来看管.一个仓库只能由一个人来看管,一个人可以看管多个仓库. 每个人有一个能力值pi,如果他看管k个仓库,那么所看管的每个仓库的安全值为 pi/k(向下取整) 如果某个仓库没有人看管,那么它的安全值为0.所有仓库的安全值L = min{ 每个仓库的安全值 } 如果雇佣一个人的工资等于他的能力值pi. 从m个人中选择一些人雇佣,问所有仓库的安全值最高是多少,在安全值最…
Pebble Solitaire Pebble solitaire is an interesting game. This is a game where you are given a board with an arrangement of small cavities, initially all but one occupied by a pebble each. The aim of the game is to remove as many pebbles as possible…
题目链接:11578 - Situp Benches 题意:健♂身♂房有两个仰卧起坐坐垫,每次调整角度要花费10元/10度,每次使用要花费15,如今给定n个人的时间顺序,和所希望的角度,求最少花费 思路:dp,dp[i][j][k]表示第i个人,一个角度为j,还有一个为k的最小花费,一个人用和两个人用的情况分开讨论,然后记录dp状态转移路径.这个输出路径让这题变得麻烦了不少.只是机智的我还是把它搞♂出♂来♂了. 代码: #include <stdio.h> #include <strin…
题目: 思路: 预处理出a[i]在哪个范围区间内是最小的,然后直接遍历a数组求答案就可以了. 这个预处理的技巧巧妙的用了之前的处理结果.(大佬tql) 代码: #include <bits/stdc++.h> #define inf 0x3f3f3f3f #define MAX 1e3 #define FRE() freopen("in.txt","r",stdin) #define FRO() freopen("out.txt",&…
考虑两个字符串,我们用dp[i][j]表示字串第到i个和字符串到第j个的总数,由于字串必须连续 因此dp[i][j]能够有dp[i][j-1]和dp[i-1][j-1]递推而来,而不能由dp[i-1][j]递推而来.而后者的条件 是字串的第i个和字符串相等. A subsequence of a given sequence is just the given sequence with some elements (possibly none) left out. Formally, give…
题目链接:10641 - Barisal Stadium 题意:逆时针给定n个点,在给m个灯,每一个灯有一个花费,要求最小花费使得全部边能被灯照到 思路:用向量叉积推断向量的顺逆时针关系,从而预处理出每一个灯能照到的边,然后因为n个点是环的,所以能够直接扩大两倍,dp时候去枚举起点就可以 状态为dp[i]表示如今照到i条边之前的边所有照亮须要的最小花费 代码: #include <stdio.h> #include <string.h> const double eps = 1e-…
题目:UVA - 10131Is Bigger Smarter? (DAG) 题目大意:给出一群大象的体重和IQ.要求挑选最多的大象,组成一个序列.严格的体重递增,IQ递减的序列.输出最多的大象数目和这些大象的序列(当中一种就能够). 解题思路:DAG上的DP.和之前的一篇相似.uva437 - The Tower of Babylon(DAG上的DP).就是将每两仅仅大象满足上面的序列要求的形成一条有向边. 之后就是DAG上的DP.然后再路径输出. 代码: #include <cstdio>…
题意:给出按照x坐标排序的n个点,让我们求出从最左端点到最右短点然后再回来,并且经过所有点且只经过一次的最短路径. 分析:这个题目刘汝佳的算法书上也有详解(就在基础dp那一段),具体思路如下:按照题目的描述比较难考虑,不如把这个问题想成两个人,分别从最左端走到最右端并且不走到重复的点所需要的最小路程,我们定义dp[i,j]表示第一个人走到第i个位置,第二个人走到第j个位置所耗费的路程,并且让第一个人的位置大于第二个人的位置,且前i个城市都已经被走过,那这样的话能走的点只有i+1,i+2,……n这…
CJOJ 1071 [Uva]硬币问题(动态规划) Description 有n种硬币,面值分别为v1, v2, ..., vn,每种都有无限多.给定非负整数S,可以选用多少个硬币,使得面值之和恰好为S?输出硬币数目的最小值和最大值. Input 第一行两个整数,n,S(1≤n≤100, 0≤S≤100000). 第二行n个整数vi-1...n(1≤vi≤S). Output 第一行两个整数,分别表示硬币数目的最小值 a 和最大值 b .无解则输出 -1 . 第二行 a 个整数分别表示使用的是第…
UVA.10066 The Twin Towers (DP LCS) 题意分析 有2座塔,分别由不同长度的石块组成.现在要求移走一些石块,使得这2座塔的高度相同,求高度最大是多少. 问题的实质可以转化为LCS(最长公共子序列)问题. 推荐一篇写的比较好的博文: 动态规划求解最长公共子序列(LCS) 核心的状态转移方程: if(a[i] == b[j]) dp[i][j] = dp[i-1][j-1] +1; else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);…
Labyrinth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1507    Accepted Submission(s): 520 Problem Description 度度熊是一只喜欢探险的熊,一次偶然落进了一个m*n矩阵的迷宫,该迷宫只能从矩阵左上角第一个方格开始走,只有走到右上角的第一个格子才算走出迷宫,每一次只能走一格,…
Break Standard Weight Time Limit: 2 Seconds                                     Memory Limit: 65536 KB                             The balance was the first mass measuring instrument invented. In its traditional form, it consists of a pivoted horizon…
uva 10718  Bit Mask  (位运算) Problem A Bit Mask Time Limit 1 Second In bit-wise expression, mask is a common term. You can get a certain bit-pattern using mask. For example, if you want to make first 4 bits of a 32-bit number zero, you can use 0xFFFFFF…
LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/A 题目: Description By definition palindrome is a string which is not changed when reversed. "MADAM" is a nice example of palindrome.…
lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730#problem/C 题目: Description The people of Mohammadpur have decided to paint each of their houses red, green, or blue. They've also decided that no two n…
C. Boredom time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a ga…