![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
动态规划
LLLBeauty
这个作者很懒,什么都没留下…
展开
-
乘法表dp
定义于字母表∑{a,b,c)上的乘法表如表1所示 表1∑乘法表 a b c a b b a b c b a c a c c 依此乘法表,对任一定义于∑上的字符串,适当加括号表达式后得到一个表达式。例如,对于字符串x=bbbba,它的一个加括号表达式为i(b(bb))(ba)。依乘法表,该表达式的值为a。试设计一个动态规划算法,对任一定义于∑上的字符串x=x1原创 2017-11-16 19:46:09 · 316 阅读 · 0 评论 -
B - Wavio Sequence
此题的意思是给出一个数字序列,让你求最长的子序列,满足: 前n+1个是升序,后n+1个是降序。(总长为2n+1) 1 2 3 4 5 4 3 2 1Sample Input10 1 2 3 4 5 4 3 2 1 10 19 1 2 3 2 1 2 3 4 3 2 1 5 4 1 2 3 2 2 1 5 1 2 3 4 5Sample Output9 9 1...原创 2018-04-28 17:49:00 · 302 阅读 · 0 评论 -
D - Prince and Princess
https://vjudge.net/contest/221630#problem/D 这个题目是公主和王子都从(0,0)走到(n,n),只不过路径不完全相同,让你找出两人的最大可以共同走过的地方。Sample Input1 3 6 7 1 7 5 4 8 3 9 1 4 3 5 6 2 8 9Sample OutputCase 1: 4解题思路: 这个题其实...原创 2018-04-28 17:42:35 · 262 阅读 · 0 评论 -
A - Partitioning by Palindromes
https://vjudge.net/contest/221629#problem/A题目意思:输入几个字符串,判断每个字符串最少切割成几串可以使得每一串都是 回文Sample Input3 racecar fastcar aaadbccbSample Output1 7 3使用DP来解决比较好。 用数组dp[i]来保存 从1到 i 个字符,至少...原创 2018-04-27 20:52:48 · 147 阅读 · 0 评论 -
C - Sharing Chocolate (dp)
真的写的心好累啊。。 感觉脑子都不转了 好吧,生活还得继续。。 刚开始接触动态压缩DP这个题的意思就是分割巧克力。 一个巧克力分成n块,并且这n块秀必须是矩形的,问是否可以分? 输入: n 行 列 a0 a1 a2…an4 3 4 6 3 2 1 2#include <iostream>#include <bits/stdc++.h>...原创 2018-04-27 16:30:02 · 407 阅读 · 0 评论 -
B - Robotruck(dp)
题目内容大概: 一个快递机器人在(0,0),快递按顺序来,这些快递要分别放到(xi,yi),但是他一次只能拿总重量小于w,机器人要按顺序送。 1 10 4 1 2 3 1 0 3 3 1 4 3 1 4 //dp[i]保存送了第i个快递并且回到原点后走过的路径长度 //dist[i]保存从原点出发,一直到i走过的路径长度 ///d[i]保存从原点直接到i的路径长度 //we...原创 2018-04-26 22:36:23 · 253 阅读 · 0 评论 -
多重集组合数问题
多重集组合数问题 有n个物品,第i件物品有ai个。不同种类的物品可以相互区分,同一种类的物品无法区分。这些物品中取出m个的话,有多少种取法?求出方案数模M的余数。#include <iostream>using namespace std;int dp[1000][1000];int main(){ int n,m,a[1000],M; cin>&...原创 2018-03-21 15:30:35 · 735 阅读 · 0 评论 -
划分数
将n划分成不超过m组,求灰分方法 模M的余数。 输入:n,m,M 4 3 10000将i分成不超过j份,当每一项都大于0时,有dp[i-j][j]种,当有0时,有dp[i][j-1]种 #include <iostream>#include <bits/stdc++.h>using namespace std;int main(){ in...原创 2018-03-18 17:47:35 · 575 阅读 · 0 评论 -
最长上升子序列
有一个长度为n的数列{a0,a1,a2…an-1},求最长上升子序列的长度。输入: 5 4 2 3 1 5输出: 3dp[i] 以 a[i] 结尾的最长上升子序列的长度 dp[i]=1; for(int j=0;j#include <iostream>#include <bits/stdc++.h>using namespace std;...原创 2018-03-18 14:58:36 · 178 阅读 · 1 评论 -
多重部分和问题
有n种大小不同的数字,各种各mi个,判断是否可以从这些数字之中选出若干个使他们的和恰好为K。 输入: 第一行为n 第二行为n种数字 第三行为这n中数的个数 第四行为K输出: 可以 输出”yes” 不可以 输出“no”/* 3 3 5 8 3 2 2 17 */#include <iostream>#include <bits/stdc++.h...原创 2018-03-18 13:59:02 · 244 阅读 · 0 评论 -
01背包dp
#include <iostream>#include <bits/stdc++.h>using namespace std;int n,v[100],w[100],W,dp[100][1000];int solve(){ for(int i=n-1;i>=0;i--){ for(int j=0;j<=W;j++){ ...原创 2018-03-18 12:20:52 · 146 阅读 · 0 评论 -
magic balls
The town of W has N people. Each person takes two magic balls A and B every day. Each ball has the volume aiai and bibi. People often stand together. The wizard will find the longest increasing subsequ原创 2017-12-17 19:52:02 · 330 阅读 · 0 评论 -
C - Fewest Flops
这个题的意思是: “aabbbaabaaaa” may be encoded as “2a3b2a1b4a” 给出一个字符串,将其按照每组k个字符切开,将每组的字符重新排序, let S be “uuvuwwuv” and k be 4. Then S1 is “uuvu” and has three chunks, but may be rearranged to “uuuv” whic...原创 2018-04-28 20:56:05 · 377 阅读 · 0 评论