DP动态规划
Wa_Automata
这个作者很懒,什么都没留下…
展开
-
2023河南萌新联赛第(六)场:河南理工大学 B - 这是dp题吗
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K。原创 2023-08-22 21:03:09 · 93 阅读 · 0 评论 -
2023河南萌新联赛第(六)场:河南理工大学 C - 旅游
时间限制:C/C++ 1秒,其他语言2秒空间限制:C/C++ 262144K,其他语言524288K。小C喜欢旅游,现在他要去DSH旅游,DSH里有nnn个城市和 $n-1$ 条双向道路(每条道路长度为1),每条道路连接两个城市,并且任意两个城市都可以通过这些的道路互相到达。现在小C要使用魔法指定传送到DSH里的一个城市,作为他旅游的出发城市,小C旅游遵从以下原则:原创 2023-08-22 16:23:45 · 614 阅读 · 0 评论 -
2023河南萌新联赛第(六)场:河南理工大学 H - 左右横跳
小D想和你玩个游戏,游戏规则如下:给出 $m$ 个高度为 $n$ 的柱子,每个柱子的每一单位长度上有一定的分数 $a_{ij}$ 表示在第 $j$ 个柱子上的第 $i$ 个单位长度上的分数,玩家可以选择从任意一个柱子上单位长度为 $1$ 处开始,有以下两种操作:原创 2023-08-21 12:47:32 · 134 阅读 · 0 评论 -
第十三届蓝桥杯大赛软件类国赛 C/C++ 大学B组 试题 F: 费用报销
# [P8803 \[蓝桥杯 2022 国 B\] 费用报销](https://www.luogu.com.cn/problem/P8803)### 试题 F: 费用报销#### 思路:将月日转化成这一年的第几天,然后进行DP原创 2023-03-04 10:50:03 · 406 阅读 · 0 评论 -
POJ - 1976 A Mini Locomotive(DP)
# [POJ - 1976 A Mini Locomotive](http://poj.org/problem?id=1976)### 题意: - 给定n个数,要求三段连续的m个数之和最大### 分析:- 为了求某个子段的和,我们通过前缀和预处理- 题目上给出 $m原创 2023-01-13 12:13:39 · 98 阅读 · 0 评论 -
HDU 2089 不要62(数位DP,DFS写法)
HDU 2089 不要62calcal函数(一般情况):注意每次初始化 DPDP 数组为 −1−1,长度 len=0len=0基本参数:len:len: 数位长度,一般根据这个来确定数组范围a_i:a i : 每个数位具体数字返回值 returnreturn 根据题目的初始条件来确定前导 00 以及 prepreDFS 函数(一般情况):变量 resres 来记录答案,初始化一般为 00变量 upup 表示能枚举的最高位数采用记忆化搜索的方式:if (!limit &&原创 2022-09-09 12:47:04 · 164 阅读 · 0 评论 -
HDU - 1087 Super Jumping! Jumping! Jumping!(LIS,最大上升子序列求和,nlogn做法)
因为这道题数据范围比较小,暴力n^2做法就可以AC,后面给大家介绍一种 当 1原创 2021-07-31 11:31:31 · 120 阅读 · 0 评论 -
2022河南萌新联赛第(一)场:河南工业大学 J - 樱果运输
二维费用的背包问题,两个约束条件为卡车数量和资金数。最后控制资金数循环判断卡车数即可。时间复杂度:O(n∗n∗y)O(n∗n∗y)O(n∗n∗y)原创 2022-07-10 20:59:39 · 116 阅读 · 0 评论 -
HDU - 1260 Tickets(线性DP)
Problem DescriptionJesus, what a great movie! Thousands of people are rushing to the cinema. However, this is really a tuff time for Joe who sells the film tickets. He is wandering when could he go back home as early as possible.A good approach, reducing原创 2022-07-07 16:27:06 · 86 阅读 · 0 评论 -
POJ - 3616 Milking Time(DP+LIS)
DescriptionBessie is such a hard-working cow. In fact, she is so focused on maximizing her productivity that she decides to schedule her next N (1 ≤ N ≤ 1,000,000) hours (conveniently labeled 0…N-1) so that she produces as much milk as possible.Farmer John原创 2022-07-06 15:45:00 · 95 阅读 · 0 评论 -
HDU - 2859 Phalanx(DP)
Problem DescriptionToday is army day, but the servicemen are busy with the phalanx for the celebration of the 60th anniversary of the PRC.A phalanx is a matrix of size n * n, each element is a character (a~z or A~Z), standing for the military branch of t原创 2022-07-04 16:32:05 · 110 阅读 · 0 评论 -
HDU - 1078 FatMouse and Cheese(记忆化搜索DP)
Problem DescriptionFatMouse has stored some cheese in a city. The city can be considered as a square grid of dimension n: each grid location is labelled (p,q) where 0原创 2022-07-04 16:18:54 · 109 阅读 · 0 评论 -
POJ - 1458 Common Subsequence(最长公共子序列)
DescriptionA subsequence of a given sequence is the given sequence with some elements (possible none) left out. Given a sequence X = < x1, x2, …, xm > another sequence Z = < z1, z2, …, zk > is a subsequence of X if there exists a strictly increasing sequen原创 2022-07-02 02:16:12 · 148 阅读 · 0 评论 -
HDU - 1114 Piggy-Bank(完全背包)
Problem DescriptionBefore ACM can do anything, a budget must be prepared and the necessary financial support obtained. The main income for this action comes from Irreversibly Bound Money (IBM). The idea behind is simple. Whenever some ACM member has any s原创 2022-07-02 02:00:03 · 219 阅读 · 0 评论 -
HDU - 1069 Monkey and Banana(DP+LIS)
Problem DescriptionA group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana at the roof of a building, and at the mean time, provide the monkey with some blocks. If the monkey is clever enough, it shall be abl原创 2022-06-30 19:33:16 · 134 阅读 · 0 评论 -
HDU - 1024 Max Sum Plus Plus(DP)
Problem DescriptionNow I think you have got an AC in Ignatius.L’s “Max Sum” problem. To be a brave ACMer, we always challenge ourselves to more difficult problems. Now you are faced with a more difficult problem.Given a consecutive number sequence S1, S2,原创 2022-06-30 18:56:59 · 177 阅读 · 0 评论 -
PTA L3-032 关于深度优先搜索和逆序对的题应该不会很难吧这件事 (30 分)
背景知识深度优先搜索与 DFSDFSDFS 序深度优先搜索算法(DFS)(DFS)(DFS)是一种用于遍历或搜索树或图的算法。以下伪代码描述了在树 TTT 上进行深度优先搜索的过程:令 rrr 为树 TTT 的根,调用 DFS(T,r,L)DFS(T,r,L)DFS(T,r,L) 即可完成对 TTT 的深度优先搜索,保存在链表 LLL 中的排列被称为 DFSDFSDFS 序。相信聪明的你已经发现了,如果枚举子节点的顺序不同,最终得到的 DFSDFSDFS 序也会不同。逆序对给定一个长度为 nnn原创 2022-06-20 23:26:14 · 1287 阅读 · 1 评论 -
POJ - 3140 Contestants Division(树形DP)
POJ - 3140 Contestants Division(树形DP)#include<iostream>#include<cstdio>#include<vector>using namespace std;typedef long long LL;const int N = 100010;vector<int> g[N];LL dp[N];inline LL LLabs(LL x){ return x<0?-x:x;}原创 2022-04-25 10:58:48 · 91 阅读 · 0 评论 -
HDU - 1561 The more, The Better(树形背包DP)
HDU - 1561 The more, The Better(树形背包DP)#include<iostream>#include<cstring>#include<vector>using namespace std;const int N = 210;int n,m;vector<int> g[N];int dp[N][N],w[N];void dfs(int u){ dp[u][1]=w[u]; for(auto &j:原创 2022-04-21 11:45:14 · 86 阅读 · 0 评论 -
HDU - 1011 Starship Troopers(树形背包DP)
HDU - 1011 Starship Troopers(树形背包DP)#include<iostream>#include<cstring>#include<vector>using namespace std;const int N = 110;int n,m;vector<int> g[N];int dp[N][N],num[N],val[N]; void dfs(int u,int fa){ int ww=(num[u]+19)原创 2022-04-20 21:58:55 · 134 阅读 · 0 评论 -
HDU - 2196 Computer(树形DP)
HDU - 2196 Computer(树形DP)#include<iostream>#include<cstring>#include<vector>using namespace std;typedef pair<int,int> PII; const int N = 10010;vector<PII> g[N];int d1[N],d2[N],df[N],dn[N];int n;void dfs_d(int u,int原创 2022-04-20 21:14:29 · 370 阅读 · 0 评论 -
HDU - 1520 Anniversary party(树形DP)
HDU - 1520 Anniversary party(树形DP+线性DP)#include<iostream>#include<cstring>#include<vector>using namespace std;const int N = 6010;vector<int> g[N];int val[N],dp[N][2],fa[N],n;void dfs(int u){ dp[u][0]=0,dp[u][1]=val[u];原创 2022-04-20 18:18:20 · 258 阅读 · 0 评论 -
POJ - 2378 Tree Cutting(树形DP)
POJ - 2378 Tree Cutting(树形DP)#include<iostream>#include<vector>using namespace std;const int N = 10010;vector<int> g[N];int sum[N],maxn[N];void dfs(int u,int fa){ for(int i=0;i<(int)g[u].size();i++) { if(g[u][i]==fa) cont原创 2022-04-20 17:55:24 · 118 阅读 · 0 评论 -
ZZULIOJ 2827: 欢度佳节(状态压缩)
ZZULIOJ 2827: 欢度佳节对于17个连通块,进行爆搜,一共2172^{17}217种情况,状态压缩的思想,用01表示是否走这个连通块,然后DFS暴力搜索,判断能否完成所有的连通块#include<bits/stdc++.h>using namespace std;typedef pair<int,int> PII;const int N = 6;const int x[] = {1,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,5};const原创 2021-12-17 19:55:51 · 350 阅读 · 0 评论 -
POJ - 1934 Trip(LCS)
POJ - 1934 Trip(LCS)#include<cstdio>#include<cstring>int n,m,len,f[110][110];char s1[110],s2[110],path[110];int max(int a,int b){return a>b?a:b;}void dfs(int i,int j,int u){ if(u>len) {puts(path+1);return;} if(s1[i]==s2[j]) {pat原创 2022-02-17 15:08:40 · 377 阅读 · 0 评论 -
POJ - 1952 BUY LOW, BUY LOWER(LDS+去重)
POJ - 1952 BUY LOW, BUY LOWER(LDS+去重)最长上升改为最长下降计算该长度的序列个数计算序列个数时不能重复输入样例1:1268 69 54 64 68 64 70 67 78 6298 87输出样例1:4 2输入样例2:54 3 2 1 1输出样例2:4 1#include <iostream>using namespace std;const int N = 5010;int a[N],f[N],g[N];i原创 2022-02-14 21:49:47 · 167 阅读 · 0 评论 -
POJ - 1737 Connected Graph,Java(计数类DP)
POJ - 1737 Connected GraphC++高精太难写了,直接用Java的大整数会方便一点常规方法import java.io.OutputStreamWriter;import java.io.PrintWriter;import java.math.BigInteger;import java.util.Scanner;public class Main { static Scanner cin = new Scanner(System.in); st原创 2022-02-14 00:37:36 · 494 阅读 · 0 评论 -
CodeForces - 559C Gerald and Giant Chess(计数DP)
https://codeforces.com/problemset/problem/559/C#include<iostream>#include<algorithm>using namespace std;typedef long long LL;typedef pair<int,int> PII;const int N = 200010, M = 2010, MOD = 1e9 + 7;PII G[M];int jc[N],jcinv[N],f[原创 2022-02-13 18:03:46 · 347 阅读 · 0 评论 -
POJ - 1180 Batch Scheduling(斜率优化DP)
POJ - 1180 Batch Scheduling(斜率优化DP)原创 2022-02-08 01:30:36 · 194 阅读 · 0 评论 -
POJ - 3017 Cut the Sequence(单调队列优化DP)
POJ - 3017 Cut the Sequence(单调队列优化DP)1.题意:给定一个长度为 NNN (N≤1e5)(N≤1e5)(N≤1e5)的序列 AAA ,要求把该序列分成若干段,在满足“““每段中所有数的和”””不超过MMM的前提下,让“““每段中所有数的最大值”””之和最小。2.分析朴素DP:状态:设f[i]表示将前i个数分为若干段,每段和不超过m时,最大值之和的最小值。转移方程:f[i]=min(f[j]+max(a[j+1],a[j+2],......a[i]))(∑k原创 2022-02-08 00:33:57 · 460 阅读 · 0 评论 -
POJ - 1821 Fence(单调队列优化DP)
POJ - 1821 Fence(单调队列优化DP)#include<cstdio>#include<algorithm>#include<deque>using namespace std;const int N=110,M=16010;struct Node{ int p,l,s;//单价;最高长度;必备点 bool operator <(const Node& t) const {return s<t.s原创 2022-02-04 23:00:21 · 277 阅读 · 0 评论 -
HDU - 5542 The Battle of Chibi(树状数组+DP)
UVA - 12983 The Battle of Chibi(树状数组+DP)HDU - 5542 The Battle of Chibi(树状数组+DP)#include<cstdio>#include<cstring>#include<algorithm>#include<vector>using namespace std;const int N = 1010, MOD = 1e9 + 7;int n,m,a[N],tr[N],f原创 2022-02-04 17:01:48 · 330 阅读 · 0 评论 -
POJ - 2228 Naptime(环形结构DP)
POJ - 2228 Naptime(环形结构DP)#include <iostream>#include <cstring>using namespace std;const int N = 4000, INF = 0x3f3f3f3f;int n,m,w[N],f[2][N][2];void solve(){ for (int i = 2; i <= n; i ++ ) for (int j = 0; j <= m;原创 2022-02-04 12:45:07 · 435 阅读 · 0 评论 -
POJ - 3585 Accumulation Degree(二次扫描与换根法)
POJ - 3585 Accumulation Degree(二次扫描与换根法)#include<cstdio>#include<cstring>#include<vector>using namespace std;typedef pair<int,int> PII;const int N = 200010, INF = 0x3f3f3f3f;vector<PII> g[N];int d[N],f[N],deg[N原创 2022-02-03 20:32:43 · 374 阅读 · 0 评论 -
POJ - 1179 Polygon(区间DP)
POJ - 1179 Polygon(区间DP)#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int N = 110, INF = 1<<15;int w[N],f[N][N],g[N][N];char op[N];int main(){ int n;cin>>n; for(int i=1;i<原创 2022-02-03 18:25:00 · 216 阅读 · 0 评论 -
POJ - 1015 Jury Compromise
POJ - 1015 Jury Compromise#include <cstring>#include <cstdio>#include <algorithm>using namespace std;const int N = 210, M = 810, base = 400;int n, m;int p[N], d[N];int f[N][21][M];int ans[N];int main(){ int T = 1;原创 2022-02-02 00:46:20 · 206 阅读 · 0 评论 -
ZZULIOJ 2829: 闯关游戏(背包DP)
ZZULIOJ 2829: 闯关游戏#include<bits/stdc++.h>using namespace std;int f[6010];signed main(){ int T;cin>>T; while(T--) { memset(f,0,sizeof f); int n,H;cin>>n>>H; int res=0,now=0,flag=0; for(int i=1;i<=n;i++) { in原创 2022-01-23 14:02:59 · 3131 阅读 · 0 评论 -
POJ - 2376 Cleaning Shifts(贪心,数据结构优化DP)
POJ - Cleaning Shifts贪心做法:对左端点排个序,判断每个区间的右端点是否覆盖下一个区间的右端点,然后替换右端点变量,最后输出需要区间数量即可。#include<iostream>#include<algorithm>#define x first#define y secondusing namespace std;typedef pair<int,int>PII;const int N = 25010;PII section[N原创 2021-11-19 19:56:50 · 353 阅读 · 0 评论 -
POJ - 3171 Cleaning Shifts(数据结构优化DP)
POJ - 3171 Cleaning Shifts(数据结构优化DP)#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>using namespace std;typedef long long LL;const int N = 10010, M = 90000;const LL INF = 1e15;int n, m, e;stru原创 2021-11-19 21:07:43 · 88 阅读 · 0 评论 -
POJ - 3666 Making the Grade(DP)
POJ - 3666 Making the Grade对单调上升和单调下降分别求一遍,取最小值即可。下面只讨论对单调上升的求法。引理:一定存在一组最优解,使得每个 BiBiBi 都是原序列中的某个值。原创 2021-11-15 18:58:14 · 250 阅读 · 0 评论