动态规划
文章平均质量分 50
理想三旬(づ ̄3 ̄)づ╭~
这个作者很懒,什么都没留下…
展开
-
瓜瓜打游戏(EASY)
题目链接: 瓜瓜打游戏(EASY)#include<stdio.h>long long int a[5005],n,p,i,j,b;int main(){ a[0]=1; scanf("%lld %lld",&n,&p); for(i=0;i<n;i++)//第i关 { scanf("%lld",&b); for(j=i;j>=0;j--)//徽章 {原创 2022-03-20 08:16:31 · 4401 阅读 · 0 评论 -
Armchairs CodeForces - 1525D
题目链接:Armchairsdp[i][j] 代表,前 i 个 1 和前 j 个 0匹配 消耗的最短时间。初始化为dp[0][i]=0;,详细细节看代码。//1 1 1 0 0 0//1 1 0 1 0 0 1//1 0 0 1 1 0 3//0 0 0 1 1 1 5#include<bits/stdc++.h>using namespace std;const int maxn=1e4+5;int a[maxn],z[maxn],o[maxn];int dp[ma原创 2022-03-14 20:13:45 · 485 阅读 · 0 评论 -
Maximum Sum of Products CodeForces - 1519D
题目链接:D. Maximum Sum of Products#include<bits/stdc++.h>using namespace std;const int maxn=5e3+5;long long a[maxn],b[maxn];long long dp[maxn][maxn];int main(){ int n; cin>>n; for(int i=1;i<=n;i++) cin>>a[i]; long long sum=0原创 2022-03-13 09:26:30 · 355 阅读 · 0 评论 -
AtCoder Beginner Contest 242 C 1111gal password
题目链接:C 1111gal password题意:长度为n的数字,每一位数字满足1<=x<=9,|x1-x2|<=1,求出有多少个数字题解:运用数位dp求解#include<bits/stdc++.h>using namespace std;const int maxn=1e6+5,mod = 998244353;long long dp[maxn][10];int main(){ for(int i=1;i<=9;i++) dp[1][i]原创 2022-03-06 20:31:07 · 587 阅读 · 0 评论 -
#10150. 「一本通 5.1 练习 1」括号配对
题目链接:[#10150. 「一本通 5.1 练习 1」括号配对](https://loj.ac/p/10150题目描述Hecy 又接了个新任务:BE 处理。BE 中有一类被称为 GBE。以下是 GBE 的定义:空表达式是 GBE如果表达式 A 是 GBE,则 [A] 与 (A) 都是 GBE如果 A 与 B 都是 GBE,那么 AB 是 GBE下面给出一个 BE,求至少添加多少字符能使这个 BE 成为 GBE。输入格式输入仅一行,为字符串 BE。输出格式输出仅一个整数,表示增加的最少原创 2022-03-01 21:21:20 · 190 阅读 · 0 评论 -
魔法少女 计蒜客 - T1551(动态规划)
题目链接:魔法少女前些时间虚渊玄的巨献小圆着实火了一把。 在黑长直(小炎)往上爬楼去对抗魔女之夜时,她遇到了一个问题想请你帮忙。 因为魔女之夜是悬浮在半空的,所以她必须要爬楼,而那座废墟一共有 nn 层,而且每层高度不同,这造成小炎爬每层的时间也不同。不过当然,小炎会时间魔法,可以瞬间飞过一层或者两层[即不耗时]。但每次瞬移的时候她都必须要至少往上再爬一层(在这个当儿补充魔力)才能再次使用瞬移。爬每单位高度需要消耗小炎 11 秒时间。 消灭魔女之夜是刻不容缓的,所以小炎想找你帮她找出一种最短时间方案能通往原创 2021-10-16 11:19:11 · 111 阅读 · 0 评论 -
Cheapest PalindromePOJ - 3280(动态规划dp)
题目链接:Cheapest Palindrome题意:给你一个字符串,每个字符增加或者删除都会有花费,求构成字符串的最小的花费题解:该题为动态规划,dp[i][j]表示从i到j是回文串所花费的代价,因为增加一个字符和删除一个字符是等价的,因此花费选择这两个中最小的花费#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[5000][5000];int原创 2021-10-04 21:13:17 · 58 阅读 · 0 评论 -
数位dpPOJ 3252 Round Numbers
题目链接:[Round Numbers](https://vjudge.net/problem/POJ-3252参考博客链接:博客链接#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int n,m;int dp[50][50][50];int b[50];int dfs(int g,int u,int v,int l){ if(g==0) retur原创 2021-09-18 21:03:08 · 90 阅读 · 0 评论 -
搬寝室 HDU - 1421
题目: 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2k件过去就行了.但还是会很累,因为2k也不小是一个不大于n的整数.幸运的是xhd根据多年的搬东西的经验发现每搬一次的疲劳度是和左右手的物品的重量差的平方成正比(这里补充一句,xhd每次搬两件东西,左手一件右手一件).例如xhd左手拿重量为3的物品,右手拿重量为6的物品,则他原创 2021-07-31 21:30:58 · 43 阅读 · 0 评论 -
Substring HDU - 6948
题意:您将获得一个仅包含小写字母的字符串S[1…N]。现在您需要找到最长的子字符串S[l…r],这样每个字母(atoz)在子字符串中出现的次数不超过K次。您只需要输出长度(r−l+1)最长子串的。输入多个测试用例。每个测试用例包含一个整数K(1≤K≤N) 一行中有一个字符串。保证输入字符串的长度之和不超过4×105输出对于每个测试用例,在一行中打印一个整数,表示最长子字符串的长度。样本输入1 ABCABC2 ABCABC2 aaabbccc样本输出3.6.4.思路:利用boo原创 2021-07-31 09:55:11 · 92 阅读 · 0 评论 -
[POJ-1276] -多重背包
文章目录前言一、多重背包是什么?二、二进制优化2.代码前言一、多重背包是什么?多重背包:有N种物品和一个容量为T的背包,第i种物品最多有M[i]件可用,价值为P[i],体积为V[i],求解:选哪些物品放入背包,可以使得这些物品的价值最大,并且体积总和不超过背包容量。对比一下完全背包,其实只是多了一个限制条件,完全背包问题中,物品可以选择任意多件,只要你装得下,装多少件都行。题目链接二、二进制优化二进制优化: 假设某一面值的票据有100张,我们并不需要将100张票据全部加入运算数组,我原创 2021-07-26 16:25:09 · 240 阅读 · 0 评论 -
~背包问题
The aspiring Roy the Robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. He has decided to work in the lucrative business of bank robbery only for a short while, before原创 2021-06-11 20:21:02 · 114 阅读 · 0 评论 -
Apple Catching(苹果捕捉)
It is a little known fact that cows love apples. Farmer John has two apple trees (which are conveniently numbered 1 and 2) in his field, each full of apples. Bessie cannot reach the apples when they are on the tree, so she must wait for them to fall. Howe.原创 2021-05-22 21:30:56 · 209 阅读 · 0 评论 -
动态规划dp
You are planning to buy an apartment in a nn-floor building. The floors are numbered from 11 to nn from the bottom to the top. At first for each floor you want to know the minimum total time to reach it from the first (the bottom) floor.Let:aiai for all原创 2021-05-22 21:02:16 · 120 阅读 · 0 评论