UVA 10827 Maximum sum on a torus (LA)】的更多相关文章

算法入门经典训练指南88页练习 ::这道题只要把原矩阵扩大4倍,那么其跟最大子矩阵的题目就很类似,把二维转化成一维,求最大的序列和,不过这个序列的长度不能超过n. 长度不能超过n? 那这道题又跟hdu 3415 HDU 3415 Max Sum of Max-K-sub-sequence (单调队列) #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #…
题目大意:UVa 108 - Maximum Sum的加强版,求最大子矩阵和,不过矩阵是可以循环的,矩阵到结尾时可以循环到开头.开始听纠结的,想着难道要分情况讨论吗?!就去网上搜,看到可以通过补全进行处理,也是,通过补全一个相同的,问题就迎刃而解了,所以把n*n的矩阵扩展成2n*2n的矩阵就好了. #include <cstdio> #include <cstring> #define MAXN 160 int a[MAXN][MAXN], sum[MAXN][MAXN]; int…
题目链接:UVA - 10827 题意描述:给出一个n*n矩阵,把第一行和最后一行粘一起,把第一列和最后一列粘一起,形成一个环面,求出这个环面中最大的矩阵和. 算法分析:首先复制n*n这个矩阵,形成由4个这样小矩阵组成的大矩阵,然后在这个大矩阵里找出最大矩阵和,一看貌似和poj1050这道题有些相似,但是这道题数据大一些,O(150^4)应该会超时吧.我们可以这样想,先枚举这个最大和矩阵的左上角在大矩阵中的位置,然后枚举最大和矩阵的行数和列数,在枚举过程中处理最大和,然后更新答案即可. #inc…
两个暴力题.. 题目传送:11827 Maximum GCD AC代码: #include <map> #include <set> #include <cmath> #include <deque> #include <queue> #include <stack> #include <cstdio> #include <cctype> #include <string> #include <…
题目链接:https://codeforces.com/contest/1373/problem/D 题意 给出一个大小为 $n$ 的数组 $a$,下标为 $0 \sim n - 1$,可以进行一次反转一个区间中元素的操作,问偶数下标元素的最大和, 题解 如果反转区间长度为奇数,则下标奇偶性不同的元素间不会互换,所以反转的区间长度为偶数,反转后的区间可以看作相邻元素两两交换所得. 如:1 2 3 4 反转后为 4 3 2 1,偶数下标元素由 1 3 变成了 2 4 ,可以看作 1 与 2 相交换…
[LeetCode]895. Maximum Frequency Stack 解题报告(Python) 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 题目地址:https://leetcode.com/problems/maximum-frequency-stack/description/ 题目描述: Implement FreqStack, a class which simulates the operation of a…
[LeetCode]113. Path Sum II 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.me/ 题目地址:https://leetcode.com/problems/path-sum-ii/description/ 题目描述: Given a binary tree and a sum, find all root-to-leaf paths where each…
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=44  Maximum Sum  Background A problem that is simple to solve in one dimension is often much more difficult to solve in more th…
这道题用暴力解法+动态规划.分析如下: 对于某个1*m的矩阵,即一个数列,求其maximal sub-rectangle,可以通过求最大长连续字串和来求得(这个用到了动态规划). 那么对于n*m的矩阵,将每列的各个数字求和,将得到一个1*m的矩阵,用上文所说的方法求得的最大和即为该n*m矩阵的所有行数为n的子矩阵中的最大子矩阵和. 那么这道题,通过枚举所有行数为1.2.3.....N 的矩阵(暴力),分别用上述方法压缩矩阵求最大连续字串和,找出其中最大值,即为所求结果. 我的解题代码如下: #i…
在完成一个Access表中数据统计时,需要统计指定字段的和,使用到了Sum函数,但统计时发现,指定条件查询统计时有可能返回空值(Null),导致对应字段显示为空白,正常应显示为0.基本思路是在获取记录集RS后进行判断,然后设置为0. 今天突然想到iif,于是又测试了一篇,比之前的简单多了,关键代码: select iif(isnull(sum(求和字段)),0,sum(求和字段)) as 求和字段别名 from 表名 where 条件…
B. Maximum of Maximums of Minimums You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and ta…
题意:对于n个数X[0]~X[n-1],但你不知道它们的值,通过逐步提供给你的信息,你的任务是根据这些信息回答问题,有三种信息如下: I p  v : Xp = v;    Xp 的值为v I p q v :  Xp ^ Xq = v;   Xp 异或Xq的值为v Q k X1 X2 X3 ..... Xk  : 问X1异或X2异或X3....异或Xk的值为多少? 解题思路:先看处理部分(I),有两种 I 一种 是后面有两个整数的,一种是后面有三个整数的,(这里的输入要注意整数有可能是好几个字符…
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1154 题意: 有一块椭圆形的地.在边界上选n(0≤n<2^31)个点并两两连接得到n(n-1)/2条线段.它们最多能把地分成多少个部分? 分析: 本题需要用到欧拉公式:在平面图中,V-E+F=2,其中V是顶点数,E是边数,F是面数.因此,只需要计算V和E即可(注意还要减去外面…
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4140 约瑟夫问题.... 考虑0-n-1编号出第m个 即((m%n)-1+n)%n 形象地说就是 0, 1, ..., m-1, m, m+1, ..., n-1 即出列m-1 那么我们出列m-1后,还有 0, 1, ..., m-2, m, m+1, ..., n-1 序列全都减去m,重新…
C - Maximum of Maximums of Minimums You are given an array a1, a2, ..., an consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and t…
Where is the Marble? Descriptions: Raju and Meena love to play with Marbles. They have got a lot of marbles with numbers written on them. At the beginning, Raju would place the marbles one after another in ascending order of the numbers written on th…
| 故事背景 话说有一回,X市X公司的产品经理Douni兴致冲冲的跑来和Sum(Sum,X市X公司资历8年程序猿,技能:深思.熟虑.心细.深究.技术过敏.口头禅:嗯,容我想想.坚信:只要赚钱的业务,我都可以让一枚程序猿完成,如果不行,那就再加一枚.)说:“最近公司的B2C业务不景气,需要开发代理功能,我们产品部正在开产品研讨会,要不要一起来参加.”,Sum摸了一把下巴,嘴角露出一丝诡异的笑容,目光沿着45度角向产品经理投射过去,说:“容我,想想.”.话音未落,已被Douni抬离卡座,电光火石间仿…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 单调栈 日期 题目地址:https://leetcode.com/problems/maximum-width-ramp/ 题目描述 Given an array A of integers, a ramp is a tuple (i, j) for which i < j and A[i] <= A[j]. The width of such a…
传送门 Description Secret agent Maria was sent to Algorithms City to carry out an especially dangerous mission. After several thrilling events we find her in the first station of Algorithms City Metro, examining the time table. The Algorithms City Metro…
Here is a famous story in Chinese history. That was about 2300 years ago. General Tian Ji was a high official in the country Qi. He likes to play horse racing with the king and others. Both of Tian and the king have three horses in different classes,…
分析:时间是一个天然的序,这个题目中应该决策的只有时间和车站,使用dp[i][j]表示到达i时间,j车站在地上已经等待的最小时间,决策方式有三种,第一种:等待一秒钟转移到dp[i+1][j]的状态,代价为1.第二种:如果可以则向右上车,转移到dp[i+t][j+1],无代价,t为列车行驶时间.第三种与第二种相同.初始状态为dp[0][1] = 0,其他为INF.答案为dp[T][n]. 代码如下: #include<iostream> #include<cstdio> #inclu…
题目链接:传送门 思路: 一个节点放的数越大,那么以它为根的子树的节点权值之和就越小. 所以我们要在合法的范围内,使偶数层节点的权值尽可能地大.也就是说,令它的权值是子节点的最小值,这样保证了它的子节点权值为正. 因为奇数层的节点的s已知,所以修改偶数层的节点仅影响,向下一层的节点.(因为再往下的话,路径上的权值和不随这个偶数层的节点的权值改变而改变,而是被奇数层截断了) 代码: #include <bits/stdc++.h> using namespace std; ; const int…
题意:给出一段英文,里面包含一些单词,空格和标点,单词不区分大小写,默认都为小写.按照字典序输出这些单词(这些单词不能有重复,字母全部变成小写) stringstream:包含在头文件#include<sstream>中,能将一个字符串分割,用>>输出某些元素 #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include…
题意: 给一串密码(第一行),接着再给你很多行猜测,针对每行猜测,输出两个数字,分表代表:同一列上匹配的个数,不同列上匹配的个数.注:匹配指的是一次,一旦配对,不能再与其他配对. 思路: 每接受一行猜测就匹配,扫一遍就知道哪些是同列匹配的,统计出来,作为第一个输出的数字.扫的过程中将同列匹配的guess列置为零,顺便将不匹配的secret列插进哈希可重复的set中.接着再扫一遍guess数组,把非0的数字逐个在set中的找,找到了就删掉set中对应的数字,并统计个数.结果就出来了. #inclu…
Andy's First Dictionary Description 不提英文了 直接上中文大意吧 XY学长刚刚立下了再不过CET就直播xx的flag,为了不真的开启直播模式,XY学长决定好好学习英语.于是他每天都读一篇只包含生词的英语文章,并以自己高达450的智商在一秒钟之内记忆下来. 现在给你一篇XY学长今天要读的文章,请你写一个程序,输出他都学习到了哪些单词.要求:如果文章中有相同的单词,那么仅仅输出一次:而且如果两个单词只有大小写不同,将他们视为相同的单词. Input 测试数据将输入…
据说是DAG的dp,可用spfa来做,松弛操作改成变长.注意状态的表示. 影响决策的只有顶部的尺寸,因为尺寸可能很大,所以用立方体的编号和高的编号来表示,然后向尺寸更小的转移就行了. #include<bits/stdc++.h> using namespace std; #define MP make_pair #define fi first #define se second typedef pair<int,int> pii; ; ]; ]; ]; ][]; int mai…
题目描述 给定一个有n个正整数的数组A和一个整数sum,求选择数组A中部分数字和为sum的方案数.当两种选取方案有一个数字的下标不一样,我们就认为是不同的组成方案. 输入描述: 输入为两行: 第一行为两个正整数n(1 ≤ n ≤ 1000),sum(1 ≤ sum ≤ 1000) 第二行为n个正整数A[i](32位整数),以空格隔开. 输出描述: 输出所求的方案数 示例1 输入 5 15 5 5 10 2 3 输出 4 import java.util.Scanner; /** * @autho…
传送门 debug了好一会,突然发现,输出错了,emmm......... 明天再写debug历程: (PS:ipad debug是真的繁琐) 题意: 题解: 尽管题干中给的 t 的范围很大,但是 t ≤ 50*180+678: int dp[maxn];///dp[i]:恰好唱i分钟时的最大曲目个数 AC代码: #include<bits/stdc++.h> #include<cstdio> #include<cstring> using namespace std;…
题意:给定一个非负整数c,确定是否存在a和b使得a*a+b*b=c. class Solution { typedef long long LL; public: bool judgeSquareSum(int c) { LL head = 0; LL tail = (LL)(sqrt(c)); while(head <= tail){ LL sum = head * head + tail * tail; if(sum == (LL)c) return true; else if(sum >…
题目 求和为target的数组元素组合数,含重复. 例: 输入 arr = { 1, 2, 3, 3, 4 } ,target = 6 输出 4 题解 dp[i][j]代表到数组第i-1个元素,目标和为j的组合数. 代码 package DP; public class TargetSumCnt { public static void main(String args[]) { int[] arr = { 1, 2, 3, 3, 4 }; int target = 6; int ans = t…