CodeChef CHEFSOC2 Chef and Big Soccer 水dp】的更多相关文章

Chef and Big Soccer   Problem code: CHEFSOC2 Tweet     ALL SUBMISSIONS All submissions for this problem are available. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Chef is a big fan of soccer! He loves soccer so much,…
题意:对于给定的n个字符串,可以花费a[i]  将其倒序,问是否可以将其排成从大到小的字典序,且花费最小是多少. 析:很明显的水DP,如果不是水DP,我也不会做.... 这个就要二维,d[2][maxn],d[0][i]表示第 i 个不反转是最小花费,d[1][i]表示第 i 个反转最小花费,那么剩下的就很简单了么, 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio>…
水dp第二天(背包有关) 标签: dp poj_3624 题意:裸的01背包 注意:这种题要注意两个问题,一个是要看清楚数组要开的范围大小,然后考虑需要空间优化吗,还有事用int还是long long 代码: #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N = 13000; int W[N],D[N]; int dp[N]; int main(…
题意:.... 析:从下往上算即可,水DP. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <…
[Codechef CHSTR] Chef and String Description 每次询问 \(S\) 的子串中,选出 \(k\) 个相同子串的方案有多少种. Solution 本题要求不是很高,\(O(n^2)\) 统计每个出现次数子串个数即可. 我因为一个lld WA了一晚上(猛然意识到要%d读入long long的时候,之前一直没有翻车的原因是开了全局,如果是局部又不初始化就瞬间gg了,然鹅这个错误本地查不出来) #include <bits/stdc++.h> using na…
题意: M*N的grid,每个格上有一个整数. 小明从左上角(1,1)打算走到右下角(M,N). 每次可以向下走一格,或向右走一格,或向右走到当前所在列的倍数的列的位置上.即:若当前位置是(i,j),可以走到(i,k*j) 问取走的最大和是多少. 思路: 水DP...边界的初始化要考虑.(因为有负数). 代码: int n,m; int a[30][1005]; int dp[30][1005]; int main(){ int T; cin>>T; while(T--){ cin>&g…
Chef and Apple Trees Chef loves to prepare delicious dishes. This time, Chef has decided to prepare a special dish for you, and needs to gather several apples to do so. Chef has N apple trees in his home garden. Each tree has a certain (non-zero) num…
 题意 给你一棵由 N 个节点构成的树 T.节点按照 1 到 N 编号,每个节点要么是白色,要么是黑色.有 Q 组询问,每组询问形如 (s, b).你需要检查是否存在一个连通子图,其大小恰好是 s,并且包含恰好 b 个黑色节点. 数据 输入第一行,包含一个整数 T,表示测试数据组数.对于每组测试数据: 第一行包含两个整数 N 和 Q,分别表示树的节点个数和询问个数. 接下来 N - 1 行,每行包含两个整数 ui 和 vi,表示在树中 ui 和 vi 之间存在一条边. 接下来一行包含 N 个整数…
All submissions for this problem are available. Chef likes numbers and number theory, we all know that. There are N digit strings that he particularly likes. He likes them so much that he defines some numbers to be beautiful numbers based on these di…
Disciption Chef has recently learnt Function and Addition. He is too exited to teach this to his friend Churu. Chef and Churu are very fast friends, they share their knowledge whenever they meet. Chef use to give a lot of exercises after he teaches s…
Another OCD Patient Problem Description Xiaoji is an OCD (obsessive-compulsive disorder) patient. This morning, his children played with plasticene. They broke the plasticene into N pieces, and put them in a line. Each piece has a volume Vi. Since Xi…
https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4441 题意:有n个靶子,每个靶子有3个val,需要满足3钟情况分别得到他们的val.问最大的得分. sl :很水的dp, 记录下当前的4个状态,分别是,不选,选(左边选右边不选,左边不选右边选,左右多不选,左边右边都选),转移很简单了. 训练时看错题逗比了半天,逗. #inc…
题意:       给你一些被占用的时间点,然后有一些询问,每次输出大于等于询问时间的没被占用的最小的那个时间. 思路:       直接把所有用过的时间标记上,然后倒着更新一遍当前最小空余时间,或者用set做,两个都在下面写代码了,水题不解释了,直接看看代码就懂了. #include<stdio.h> #include<string.h> #define N 200000 + 10 int dp[N] ,mark[N]; int main () { int n ,m ,i ,a…
HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1]和dp[i-2]里面选一个就好 #include <bits/stdc++.h> #define ll long long #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0) #define pp pair<int,i…
Permutation Counting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1171    Accepted Submission(s): 587 Problem Description Given a permutation a1, a2, … aN of {1, 2, …, N}, we define its E-va…
something wrong with my new blog! I can't type matrixs so I come back. qwq 题目:https://www.codechef.com/problems/BIKE 题解 是我naive了,二维和一维其实差不多 首先,n很小,t很大,什么算法?矩阵乘法!没跑了 然后矩阵里填什么?一条边是两个值啊,还要一个%n一个%(n - 1),怎么搞 我们设计一个多项式\(x^{a}y^{b}\),x指数(也就是a)代表前轮加上一条边的值后取…
Portal --> CC Chef and Graph Queries Solution 快乐数据结构题(然而好像有十分优秀的莫队+可撤销并查集搞法qwq) 首先考虑一种方式来方便一点地..计算一个图的联通块数量:我们可以考虑容斥,维护每个连通块的生成树,然后\(n-\)生成树边数就是答案了 这样有一个好,加边的时候比较好处理,但是光这样并不能解决我们的问题 ​ 顺着这个思路思考,先不考虑时间复杂度,对于一个询问,考虑将编号为\(l\sim r\)的边一条一条加入第\(1\sim l-1\)条…
搬寝室 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description 搬寝室是很累的,xhd深有体会.时间追述2006年7月9号,那天xhd迫于无奈要从27号楼搬到3号楼,因为10号要封楼了.看着寝室里的n件物品,xhd开始发呆,因为n是一个小于2000的整数,实在是太多了,于是xhd决定随便搬2*k件过去就行了.但还是会很累,因为2*k也不小是一个不…
Read problems statements in Mandarin Chineseand Russian. Problem Statement Chef has a undirected graph G. This graph consists of N vertices and M edges. Each vertex of the graph has an unique index from 1 to N, also each edge of the graph has an uniq…
最近会多做点巩固基础的题目 #include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #include<cstdlib> #include<cmath> #include<string> #include<vector> #include<stack> #include<queue> #includ…
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tas…
点此看题面 大致题意: 有\(N\)个学生去食堂打饭,每个学生有两个属性:打饭时间\(a_i\)和吃饭时间\(b_i\).现要求将这些学生分成两队分别打饭,求最早何时所有人吃完饭. 贪心 首先,依据贪心的思想,肯定是吃饭时间长的先打饭,因此可以将其按吃饭时间先排序预处理一遍. 如何\(DP\) 贪心完,就是\(DP\)了. 个人认为三维\(DP\)还是非常好想的:用\(f_{i,j,k}\)表示当前轮到第\(i\)个学生.在两个窗口打饭分别用了\(j\)和\(k\)个单位时间时最早吃完的时间.…
题目链接:https://www.rqnoj.cn/problem/169 题意: 给出行驶1-10公里的费用(所有车一样),可以倒车,问行驶n公里的最小费用. 题解: 大水题... (=´ω`=) 表示状态: dp[i] = min cost i:行驶了i公里 找出答案: ans = dp[n] 如何转移: now: dp[i] dp[i+j] = min dp[i] + c[j] 枚举倒车行驶j公里 边界条件: dp[0] = 0 others = -1 AC Code: // state…
+;],dp1[][],dp2[][]; map<      memset(GPA,,     ;i<=;i++) hash[i]=;     ;i<=;i++) hash[i]=;     ;i<=;i++) hash[i]=;     ;i<=;i++) hash[i]=;     ;i<=;i++) hash[i]=;     GPA[]=]=]=     GPA[]=]=     memset(dp2,,     ;i<=;i++) {         ;…
目录 @description@ @solution@ @accepted code@ @details@ @description@ 定义 dp 序列: \[dp(1) = K\\ dp(n) = A\times dp(n-1) + B\times \sum_{i=1}^{n-1}dp(i)\times dp(n-i)\] Q 次询问,每次询问给出 L, R,求 \(\sum_{i=L}^{R}dp(i)^2\),对 10^9 + 7 取模. 原题戳我查看owo. @solution@ 考虑写…
题目: http://poj.org/problem?id=1836 没读懂题,以为身高不能有相同的,没想到排中间的两个身高是可以相同的.. #include <stdio.h> #include <string.h> #include <iostream> ], dpl[]; int main() { int n; ]; while(scanf("%d", &n) != EOF) { ; i <= n; i++) { std::cin…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1231 题意: 给你一个整数序列,求连续子序列元素之和最大,并输出该序列的首尾元素(若不唯一,输出首坐标最小的:首坐标相同输出尾坐标最小的). 题解: O(N)做法. 定义sum为当前坐标i之前某一段元素[x,i-1]之和. 三种情况: (1)sum > 0:说明之前的和对答案有贡献,更新sum += a[i],tail = a. (2)sum < 0:前面的答案是拖后腿的...还不如从a[i]重新…
https://vjudge.net/problem/CodeChef-FNCS 题意: 思路: 用分块的方法,对每个函数进行分块,计算出该分块里每个数的个数,这样的话也就能很方便的计算出这个分块里所有数的和. 用树状数组维护数组的话可以很方便的计算出某个区间内所有数的和以及修改某个数. 每次查询时,如果在中间块的函数,我们直接加上sum[i](sum[i]为预处理的每一块的和),对于两边的函数,就用树状数组快速求一下和即可. #include<iostream> #include<al…
题目大意:给你一个长度为$n$的数列$a_i$,定义$f_i=\sum_{j=l_i}^{r_i} num_j$. 有$m$个操作: 操作1:询问一个区间$l,r$请你求出$\sum_{i=l}^{r} f_i$. 操作2:将$a_x$变成$y$. 此题貌似正常做都不是很好做,考虑用一些奇奇怪怪的做法(比如说分块) 考虑到此题数列在不断地变化,我们考虑用树状数组来维护序列$a$,查询$f_i$的值可以在$O(log n)$的时间内完成. 如果这么做,单次询问的复杂度是$O(n log n)$的,…
CHEFSIGN: 大厨与符号序列题目描述 大厨昨天捡到了一个奇怪的字符串 s,这是一个仅包含‘<’.‘=’和‘>’三种比较符号的字符串. 记字符串长度为 N,大厨想要在字符串的开头.结尾,和每两个字符之间插入一个正整数,共 N + 1 个数.大厨希望插入数字之后,这些比较符号所表达的含义是正确的.举个例子,如果 在‘<’前后分别插入 a 和 b,那么应当有 a < b.对于‘=’和‘>’也是类似的. 大厨可以在 [1,P] 中任意选择数字插入,同一个数也可以被插入到多个位置…