计蒜客 蓝桥杯模拟 瞬间移动 dp】的更多相关文章

  在一个 n \times mn×m 中的方格中,每个格子上都有一个分数,现在蒜头君从 (1,1)(1,1) 的格子开始往 (n, m)(n,m) 的格子走.要求从 (x_1,y_1)(x1​,y1​) 到 (x_2,y_2)(x2​,y2​) ,满足 x_2 \ge x_1,\ y_2 \ge y_1x2​≥x1​, y2​≥y1​ .请问蒜头君从 (1,1)(1,1) 的点到 (n,m)(n,m) 最多可以得多少分? 每个格子的分数只能得到一次,其中 (1,1)(1,1) 和 (n,m)(…
问题描述 一天蒜头君得到 n 个字符串 si​,每个字符串的长度都不超过 10. 蒜头君在想,在这 n 个字符串中,以 si​ 为后缀的字符串有多少个呢? 输入格式 第一行输入一个整数 n. 接下来 n 行,每行输入一个字符串 si​. 输出格式 输出 n 个整数,第 i 个整数表示以 si​ 为后缀的字符串的个数. 数据范围 对于 50\%50% 的数据,1≤n≤10^3. 对于 100\%100% 的数据,1 ≤n≤10^5. 所有的字符串仅由小写字母组成. 样例输入 3ba a aba 样…
在一张 n 行 m 列的方格地图上放置一些守卫,每个守卫能守护上.左.右三个方向上相邻的方格和自己所在的方格.如下图,红色的方格放置守卫,绿色的方格为该守卫守护的区域. 现在要求在地图上放置若干个守卫,让每个方格至少被一个守卫守护(可以同时被多个守卫守护),但是有些方格上不能放置守卫(这个方格也需要被守护),求出最少需要多少个守卫才能满足条件. 输入格式 第一行输入两个整数 n, m. 接下来输入一个 n×m 的矩阵.矩阵中元素为 0 表示该位置不能放置守卫,为 1 表示该位置能放置守卫.元素之…
用 0,1,2,3⋯70,1,2,3 \cdots 70,1,2,3⋯7 这 888 个数组成的所有整数中,质数有多少个(每个数字必须用到且只能用一次). 提示:以 000 开始的数字是非法数字. 代码: #include <iostream> #include <cstdio> using namespace std; ]; int ispri(int n) { ||n==); !=&&n%!=); ;i*i<=n;i+=) ||n%(i+)==); ; }…
给你一个从 n×nn \times nn×n 的矩阵,里面填充 111 到 n×nn \times nn×n .例如当 nnn 等于 333 的时候,填充的矩阵如下.   1 1 2 3 2 4 5 6 3 7 8 9 现在我们把矩阵中的每条边的中点连起来,这样形成了一个新的矩形,请你计算一下这个新的矩形的覆盖的数字的和.比如,n=3n = 3n=3 的时候矩形覆盖的数字如下.     1 2 2 4 5 6 3 8 那么当 nnn 等于 101101101 的时候,矩阵和是多少? 代码: #i…
计算二维前缀和,节省时间.容斥定理. 代码: #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <iomanip> #include <ostream> using namespace std; ][]; int n,q,x,y,w,a,b,c,d; int ma…
Floyd算法,最短路,判断a,b是否相等. 代码: #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <iomanip> using namespace std; int k; ][]; int main() { string a,b,c,d; cin>>a&g…
代码: #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> #include <iomanip> using namespace std; int n; ][]; int check(int x,int y,int k) { ;i < ;i ++) { ; ; } int xx,yy; ;…
递归式移项得Ai+1 = 2Ai + 2Ci - Ai-1; 1.A2 = 2A1 + 2C1 - A0; 2.A3 = 2A2 + 2C2 - A1; . . . n.An+1 = 2An + 2Cn - An-1;如此的1式带入2式,之后的2式带入3式,直到n式被更新为An+1 = n+1A1 + (2nC1 + 2(n-1)C2 + ... + 2Cn - nA0,只剩下A1未知了.代码: #include <cstdio> #include <cstdlib> #inclu…
题目链接 取数游戏 思路:dp(x, y)表示先手在区间[x, y]能取得的最大分数.当先手取完,就轮到后手去,后手一定会选择当前能令他得到最大分数的策略,其实当先手在[x, y]区间两端取走一个数,那么后手面临两个状态[x+1, y]和[x, y-1],先手想要取得最大值,一定会想让后手取这两种状态中的较小值,设[x, y]区间的数字和为sum,转移方程就是dp(x, y) = max{sum - dp(x+1, y), dp(x, y-1)}.边界就是只有一个数的时候,即x==y. 关于博弈…