Codeforces 698A - Vacations - [简单DP]】的更多相关文章

题目链接:http://codeforces.com/problemset/problem/698/A 题意: 有 $n$ 天假期,每天有四种情况:0.体育馆不开门,没有比赛:1.体育馆不开门,有比赛:2.体育馆开门,没有比赛:3.体育馆开门,有比赛. 每天都可以选择一件事做:休息.去体育馆运动.打比赛. 现在有一个限制条件:不能连续两天都去体育馆,或者连续两天都打比赛.要求尽量使得休息的天数最少,求出这个天数. 题解: $f[i][0,1,2]$ 表示前 $i$ 天,第 $i$ 天休息/运动/…
题目链接:点击打开链接 给定n*m 的矩阵 常数k 以下一个n*m的矩阵,每一个位置由 0-9的一个整数表示 问: 从最后一行開始向上走到第一行使得路径上的和 % (k+1) == 0 每一个格子仅仅能向↖或↗走一步 求:最大的路径和 最后一行的哪个位置作为起点 从下到上的路径 思路: 简单dp #include <cstdio> #include <algorithm> #include<iostream> #include<string.h> #incl…
题目链接 : http://codeforces.com/problemset/problem/698/A 题目大意: 阿Q有n天假期,假期中有三种安排 休息.健身.比赛.每天有三种选择条件: 0 健身房不开门 没有比赛 1 健身房不开门    有比赛 2 健身房开门     没有比赛  3 健身房开门   有比赛 请给阿Q 合理的安排他的假期[阿Q不能连着两天健身或者连着两天比赛],使得阿Q的休息天数最少. 解题思路: ans=n,最多休息ans天 第一天是3 则a[0]=0,ans--; 只…
要么去体育馆,要么去比赛,要么闲在家里 给出每一天体育馆和比赛的有无情况,要求连续两天不能去同一个地方 问最少闲几天 DP方程很容易看出 dp(第i天能去的地方) = min(dp(第i-1天的三种情况)) : dp(第i天呆在家里) = min(dp(第i-1天的三种情况))+1: #include <cstdio> #include <iostream> using namespace std; #define inf 0x3f3f3f3f ],ans[][],n; void…
题目链接:http://codeforces.com/problemset/problem/279/C 题意: 给出 $n$ 个整数 $a[1 \sim n]$,$m$ 个查询,对于一个查询 $[l_i,r_i]$,对应于子段 $a[l_i], a[l_i+1], \cdots, a[r_i]$,需要你判断这个子段是不是单峰的. 此处的单峰,指的是,开始时是一段单调不减的,然后以一段单调不增结束:同时这两段的长度为零也是可以的. 题解: 令 $f[i]$ 表示第 $i$ 个整数往前走,保持单调不…
题目链接:http://codeforces.com/problemset/problem/180/C 题意: 有一段字符串,包含大小写字母,每次可以将其中一个字母由大写变成小写,或者小写变成大写.要求这个字符串最终变成任意大写字母都在任意小写字母的前面的情况.问最少变换多少个字母可达到要求. 题解: $f[i][0,1]$ 表示前 $i$ 个字母,第 $i$ 个字母为 $0$大写 / $1$小写,最少要改变的字母数. AC代码: #include<bits/stdc++.h> #define…
题目链接:http://codeforces.com/problemset/problem/455/A 给你n个数,要是其中取一个大小为x的数,那x+1和x-1都不能取了,问你最后取完最大的和是多少. 简单dp,dp[i]表示取i时zui最大和为多少,方程为dp[i] = max(dp[i - 1] , dp[i - 2] + cont[i]*i). #include <bits/stdc++.h> using namespace std; typedef __int64 LL; ; LL a…
Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Noura Boubou is a Syrian volunteer at ACM ACPC (Arab Collegiate Programming Contest) since 2011. She graduated from Tishreen Un…
C. Writing Code Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/problem/C Description Programmers working on a large project have just received a task to write exactly m lines of code. There are n programmers working o…
D. Fedor and Essay time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After you had helped Fedor to find friends in the «Call of Soldiers 3» game, he stopped studying completely. Today, the E…
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password i…
Super Jumping! Jumping! Jumping! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33384    Accepted Submission(s): 15093 Problem Description Nowadays, a kind of chess game called “Super Jumping!…
题目链接 这道题也是简单dp里面的一种经典类型,递推式就是dp[i] = min(dp[i-150], dp[i-200], dp[i-350]) 代码如下: #include<iostream> #include <stdio.h> using namespace std; ]; int main() { ; i < ; i++) dp[i] = i; ; i < ; i++) { int minn; ) dp[i] = dp[i - ]; ) dp[i] = min…
J - 简单dp Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveni…
I - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description Nowadays, a kind of chess game called “Super Jumping! Jumping! Jumping!” is very popular in HD…
题意:给你n种花,m个盆,花盆是有顺序的,每种花只能插一个花盘i,下一种花的只能插i<j的花盘,现在给出价值,求最大价值 简单dp #include <iostream> #include<cstdio> #include<cstring> using namespace std; #define N 110 int dp[N][N],a[N][N]; int main(int argc, char** argv) { int n,m,i,j; while(sca…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2571 简单dp, dp[n][m] +=(  dp[n-1][m],dp[n][m-1],d[i][k] ) k 为m的因子 PS:0边界要初始为负数(例如-123456789)越大越好 代码: #include <stdio.h> #include <string.h> int dp[25][1005]; #define max(x,y) x > y ? x : y int m…
http://poj.org/problem?id=1189 Description 有一个三角形木板,竖直立放.上面钉着n(n+1)/2颗钉子,还有(n+1)个格子(当n=5时如图1).每颗钉子和周围的钉子的距离都等于d,每一个格子的宽度也都等于d,且除了最左端和最右端的格子外每一个格子都正对着最以下一排钉子的间隙.  让一个直径略小于d的小球中心正对着最上面的钉子在板上自由滚落,小球每碰到一个钉子都可能落向左边或右边(概率各1/2).且球的中心还会正对着下一颗将要碰上的钉子.比如图2就是小球…
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063?viewmode=contents 题目链接:http://poj.org/problem?id=1163 --------------------------------------------------------------------------------------------------------------------------------------…
Description Farmer John以及他的N(1 <= N <= 2,500)头奶牛打算过一条河,但他们所有的渡河工具,仅仅是一个木筏. 由于奶牛不会划船,在整个渡河过程中,FJ必须始终在木筏上.在这个基础上,木筏上的奶牛数目每增加1,FJ把木筏划到对岸就得花更多的时间. 当FJ一个人坐在木筏上,他把木筏划到对岸需要M(1 <= M <= 1000)分钟.当木筏搭载的奶牛数目从i-1增加到i时,FJ得多花M_i(1 <= M_i <= 1000)分钟才能把木…
简单dp 状态方程很好想,主要是初始化.... 代码: #include<iostream> #include<cstdlib> #include<cstdio> #include<cstring> using namespace std; #define MAX 1010 #define _INF -100000000 int n,m; int f[MAX][MAX]; int dp[MAX][MAX]; int main() { int t; scanf…
这一次组织了一场\(dp\)的专项考试,出了好几道经典的简单\(dp\)套路题,特开一篇博客写一下题解. Tower(双向dp) Description 信大家都写过数字三角形问题,题目很简单求最大化一个三角形数塔从上往下走的路径和.走的规则是:(i,j)号点只能走向(i+1,j)或者(i+1,j+1).如下图是一个数塔,映射到该数塔上行走的规则为:从左上角的点开始,向下走或向右下走直到最底层结束. 1 3 8 2 5 0 1 4 3 8 1 4 2 5 0 路径最大和是1+8+5+4+4 =…
题目链接:https://nanti.jisuanke.com/t/20                                         跳跃游戏二 给定一个非负整数数组,假定你的初始位置为数组第一个下标.数组中的每个元素代表你在那个位置能够跳跃的最大长度.你的目标是到达最后一个下标,并且使用最少的跳跃次数. 例如: A = [2,3,1,1,4],到达最后一个下标的最少跳跃次数为 2.(先跳跃 1 步,从下标 0 到 1,然后跳跃 3 步,到达最后一个下标.一共两次) 输入格式…
1.摆花问题 题目描述小明的花店新开张,为了吸引顾客,他想在花店的门口摆上一排花,共m盆.通过调查顾客的喜好,小明列出了顾客最喜欢的n种花,从1到n标号.为了在门口展出更多种花,规定第i种花不能超过ai盆,摆花时同一种花放在一起,且不同种类的花需按标号的从小到大的顺序依次摆列.试编程计算,一共有多少种不同的摆花方案. 输入输入共2行.第一行包含两个正整数n和m,中间用一个空格隔开.第二行有n个整数,每两个整数之间用一个空格隔开,依次表示a1.a2.……an. 输出输出只有一行,一个整数,表示有多…
link 题意:乘车,有3种票 1.20块坐1站 2.坐90分钟,50块 3.坐1440分钟,120块 现给出到达每个站的时间,问最优策略 思路: 简单DP,限定条件的3个转移方向,取最小的那个就行了 dp[i]代表到达第i个站的最小花费 /** @Date : 2017-04-10 18:19:53 * @FileName: 760D dp.cpp * @Platform: Windows * @Author : Lweleth (SoundEarlf@gmail.com) * @Link :…
链接: http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2857 题目解析: 这是去年校赛的题目,当时没做出来,现在才补,真水,这题就是一个简单dp. 看第k个人画第m幅画的时候,要考虑两个时间,1.第k-1个人画完第m幅画的时间,2.第k个人画完第m-1幅画的时间. 这两个时间的最大者+t[m][k]就是第k个人画完第m幅画的时间. 代码如下: #include <iostream> #in…
题目链接:  http://poj.org/problem?id=1088 题目要求: 一个人可以从某个点滑向上下左右相邻四个点之一,当且仅当高度减小.求可以滑落的最长长度. 题目解析: 首先要先排一下序,因为只能高度递减才能滑行.之后就很简单了,就是简单DP. 即:要求的滑坡是一条节点递减并依次相邻的最长路径,可以先根据高度将所有的点进行排序,在i点的时候,遍历0~i-1个点(升序排序,i前面的点的高度一定小于等于i),取相邻点间的大的路径长度 代码如下: #include <iostream…
Kattis - bank [简单DP] Description Oliver is a manager of a bank near KTH and wants to close soon. There are many people standing in the queue wanting to put cash into their accounts after they heard that the bank increased the interest rates by 42% (f…
http://acm.timus.ru/problem.aspx?space=1&num=1203 按照结束时间为主,开始时间为辅排序,那么对于任意结束时间t,在此之前结束的任务都已经被处理,从这个时间开始的任务都正要被处理, 因为t<=3e5,可以用简单dp解决 #include <cstdio> #include <algorithm> using namespace std; const int maxn=1e5+5; int n; typedef pair&l…
HDOJ 1501 Zipper [简单DP] Problem Description Given three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arbitrarily, but each must stay in i…