- 博客(515)
- 资源 (16)
- 收藏
- 关注
原创 DP--最长上升子序列
#include #include #include using namespace std;const int maxn = 100;int a[maxn], d[maxn], c[maxn], n;int dp(int i){ int ans = 0; for(int j=i+1; j<=n; j++) { if(a[i] < a[j]) ans = max(an
2015-11-08 14:59:57 387
原创 DP--最长公共子序列
继续用典型问题来讨论动态规划的两个特性(重叠子问题和最优子结构)。最长公共子序列(LCS)问题描述:给定两个序列,找出在两个序列中同时出现的最长子序列的长度。一个子序列是出现在相对顺序的序列,但不一定是连续的。例如,“ABC”,“ABG”,“BDF”,“AEG”,“acefg“,..等都是”ABCDEFG“ 序列。因此,长度为n的字符串有2 ^ n个不同的可能的序列。注意最长公共子
2015-11-08 12:15:10 532
原创 DP--矩阵连乘
问题:给定n个矩阵,求乘法次数的最小值1)最优子结构:一个简单的解决办法是把括号放在所有可能的地方,计算每个位置的成本,并返回最小值。对于一个长度为n的链,我们有n-1种方法放置第一组括号。例如,如果给定的链是4个矩阵。让矩阵连为ABCD,则有3种方式放第一组括号:A(BCD),(AB)CD和(ABC)D。所以,当我们把一组括号,我们把问题分解成更小的尺
2015-11-08 10:58:16 981
原创 C++ 初始化类的常量数据成员、静态数据成员、常量静态数据成员
1、const成员:只能在类中初始化#include using namespace std;class A {public: const int c = 1;};int main(){ A a; cout << a.c << endl; return 0;}2、static成员:初始化在类外,且不加static修饰#incl
2015-11-07 16:59:32 568
原创 Ubuntu中Terminal和GNOME文件管理器的互通方法和命令
1.Terminal -> GNOME文件管理器使用命令gnome-open [路径]2.GNOME文件管理器 -> Terminal需要文件管理器插件Nautilus的支持,使用下列命令下载安装Nautilussudo apt-get install nautilussudo apt-get install nautilus-open-termin
2015-11-06 22:46:53 1286
原创 DP--完全背包--HDU - 4508
本题是典型的完全背包问题for i=1..Nfor j=c..Vf[j]=max{f[j],f[j-c]+w}以上就是这类问题的基本套路你会发现,这个伪代码与01背包的伪代码只有v的循环次序不同而已。为什么这样一改就可行呢?首先想想为什么01背包中要按照v=V..0的逆序来循环。这是因为要保证第i次循环中的状态f[v]是由状态f[v-c]递推
2015-11-05 13:36:49 455
原创 DP--UVA - 116 Unidirectional TSP
DescriptionBackgroundProblems that require minimum paths through some domain appear in many different areas of computer science. For example, one of the constraints in VLSI routing problem
2015-11-04 14:02:47 468
原创 DP--UVA - 437 The Tower of Babylon
DescriptionPerhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of this tale have been forgotten. So now, in line with the educational nature of this contest, we
2015-11-04 13:30:10 485
原创 DP--UVA - 1025 A Spy in the Metro
分析:时间是单向流逝的,是一个天然的“序"。影响到决策的只有当前时间和所处的车站,所以可以用d(i,j)表示时刻i,你在车站j,最少还需要等待多长时间。边界条件是d(T,n)=0,其它d(T,i)为正无穷。有如下3种决策。决策1:等1分钟。决策2:搭乘往右开的车(如果有)。决策3:搭乘往左开的车(如果有)。程序中用到 has_train 数组,其中 has_train[t][i][
2015-11-04 13:25:10 484
原创 Ubuntu下GTK的安装、编译和测试
一、安装 1、安装gcc/g++/gdb/make 等基本编程工具$sudo apt-get install build-essential 2、安装 libgtk2.0-dev libglib2.0-dev 等开发相关的库文件$sudo apt-get install gnome-core-devel 3、用于在编译GTK程序时自动找出头文
2015-11-03 12:35:33 592
原创 Linux下rar 命令压缩和解压详解
例1:添加文件或目录到压缩档案中,使用a命令。例如把文件files1添加到abc.rar中,使用a或m命令,a命令把file1文件添加到abc.rar档案中保持原有的file1文件不变,m命令移动file1文件到file1.rar档案中(压缩完成后会删除原有的file1文件,注意:m命令只针对文件进行操作)$rar a abc.rar file1说明:如果此时abc.rar档案不存在,
2015-11-01 23:53:54 746
原创 IDDFS--UVA - 1374 Power Calculus
#include #include using namespace std;const int maxn = 15;int a[maxn], n;bool dfs(int maxc, int d, int maxd){ if((maxc<<(maxd-d)) < n) return false; if(maxc == n) return true; a[d]
2015-11-01 16:31:11 530
原创 枚举--UVA - 12325 Zombie's Treasure Chest
分析:直接枚举会超时,我们可以分情况讨论:1、s1 s2都很小,易知选择s1个2和选择s2个1的体积是一样的,但是value分别为 s2*v1 s1*v2,当前者大于后者时,显然要尽可能多的选择1,此时2的个数最多只有s1-1个,因为当2选择了s1个时,还不如选1个1;前小于后同理。这是枚举s2、s1 s2较大,选择的个数都很小,可以对选择个数枚举。#include #in
2015-11-01 15:33:05 829
原创 IDDFS--UVA - 11212 Editing a Book
分析:本题可以用迭代加深搜索算法。令最大搜索深度为maxd,当前搜索深度为d,则每次搜索都是从序列中截取一部分进行“剪贴复制”操作;考虑后继不正确的数字个数为h,可以证明每次剪切时h最多减少3证明:设当前有四个数字 a b c d ,如果把b移到c后面,则改变了a、b、c三个数的后继所以每次搜索前,当h>(maxd-d)*3 时剪枝,这里maxd-d即剩余搜索次数;搜索的核心就是截取
2015-11-01 14:16:07 488
原创 IDDFS--UESTC - 577 分数拆分
Description任何一个分数都能才成若干个单位分数(形如1/a的, a是自然数)的和。对于一个分数,表示方法有很多种,但是哪种最好呢?首先,加数少的比加数多的好,其次,加数个数相同的,最小的分数越大越好,如果还是相同,那么第二小的分数越大越好,依次类推下去。例如对于,下列方法都是合法的:但是最好的是最后一种,因为比, , , 都大。现在给出()
2015-11-01 11:34:08 564
原创 线段树-- POJ - 1195 Mobile phones
DescriptionSuppose that the fourth generation mobile phone base stations in the Tampere area operate as follows. The area is divided into squares. The squares form an S * S matrix with the rows
2015-11-01 00:31:45 458
原创 隐式图--UVA - 1601 The Morning after Halloween
分析:以当前3个小写字母的位置为状态,则问题转化为图的最短路问题。状态总数为256^3,每次转移需要5^3枚举每个小写字母下一步的走法,但是容易超时。由条件“任何一个2×2子网格中至少有一个障碍格”暗示着很多格子都是障碍,并且大部分空地都和障碍相邻,因此不是所有4个方向都能移动,因此可以把所有空格提出来建一个图。这里将原图中的空白点映射为编号,再将三个点的编号合一。预处理可以把每个空白格子的5个方
2015-10-31 19:22:27 580
原创 隐式图--UVA - 10603 Fill
分析:假设在某个时刻,第1个杯子中有v0升水,第2个杯子中有v1升水,第3个杯子中有v2升水,称当时的系统状态为(v0,v1,v2);把‘状态’看成图中的结点,可以得到状态转移图;由于无论如何倒,杯子中的水量都是整数,因此第3个杯子的水量最多只有0,1,2,3 ... ,c共c+1种可能,同理,第2个杯子的水量共有b+1种可能;而一旦两个杯子的水量一样了,则第三个杯子水量也一样,所以最多的状态不会
2015-10-31 13:48:21 725
原创 八数码--HDU - 1043 Eight
DescriptionThe 15-puzzle has been around for over 100 years; even if you don't know it by that name, you've seen it. It is constructed with 15 sliding tiles, each with a number from 1 to 15 on it,
2015-10-31 11:44:19 415
原创 贪心--HDU - 4221 Greedy?
DescriptioniSea is going to be CRAZY! Recently, he was assigned a lot of works to do, so many that you can't imagine. Each task costs Ci time as least, and the worst news is, he must do this work
2015-10-31 00:42:09 1032
原创 贪心--HDU - 4310 Hero
DescriptionWhen playing DotA with god-like rivals and pig-like team members, you have to face an embarrassing situation: All your teammates are killed, and you have to fight 1vN. There are two
2015-10-31 00:14:54 577
原创 贪心-- HDU - 4296 Buildings
Description Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building.
2015-10-30 23:56:06 631
原创 贪心--HDU - 4442 Physical Examination
InputThere are several test cases. Each test case starts with a positive integer n in a line, meaning the number of subjects(queues). Then n lines follow. The i-th line has a pair of integers (a
2015-10-30 23:16:40 530
原创 ZOJ - 1489 2^x mod n = 1
DescriptionGive a number n, find the minimum x that satisfies 2^x mod n = 1.InputOne positive integer on each line, the value of n.OutputIf the minimum x ex
2015-10-30 22:01:38 515
原创 哈希--ZOJ - 3844 Easy Task
DescriptionYou are given n integers. Your task is very easy. You should find the maximum integer a and the minimum integer b among these nintegers. And then you should replace both a and b with a-
2015-10-30 20:58:53 520
原创 凸包--HDU - 3285 Convex Hull of Lattice Points
DescriptionA lattice point is a point with integer coordinates. A lattice polygon is a polygon with all vertices lattice points. A polygon is convex if any line segment between two points of t
2015-10-29 15:11:50 694
原创 并查集--HDU - 3926 Hand in Hand
DescriptionIn order to get rid of Conan, Kaitou KID disguises himself as a teacher in the kindergarten. He knows kids love games and works out a new game called "hand in hand". Initially kids
2015-10-29 11:37:33 479
原创 Linux操作系统中,*.zip、*.tar、*.tar.gz、*.tar.bz2、*.tar.xz、*.jar、*.7z等格式的压缩与解压
zip格式压缩: zip -r [目标文件名].zip [原文件/目录名]解压: unzip [原文件名].zip注:-r参数代表递归tar格式(该格式仅仅打包,不压缩)打包:tar -cvf [目标文件名].tar [原文件名/目录名]解包:tar -xvf [原文件名].tar注:c参数代表create(创建),x参数代表extract(解包
2015-10-29 10:55:47 4672 1
原创 并查集-- HDU - 4263 Red/Blue Spanning Tree
DescriptionGiven an undirected, unweighted, connected graph, where each edge is colored either blue or red, determine whether a spanning tree with exactly k blue edges exists. Input
2015-10-29 10:23:02 588
原创 并查集--HDU - 4313 Matrix
DescriptionMachines have once again attacked the kingdom of Xions. The kingdom of Xions has N cities and N-1 bidirectional roads. The road network is such that there is a unique path between any
2015-10-29 09:29:51 593
原创 并查集--HDU - 4496 D-City
DescriptionLuxer is a really bad guy. He destroys everything he met. One day Luxer went to D-city. D-city has N D-points and M D-lines. Each D-line connects exactly two D-points. Luxer will dest
2015-10-29 08:41:50 528
原创 并查集--POJ - 2524 Ubiquitous Religions
Description当今世界有很多不同的宗教,很难通晓他们。你有兴趣找出在你的大学里有多少种不同的宗教信仰。你知道在你的大学里有n个学生(0 Input有多组数据。对于每组数据:第一行:两个整数n和m。以下m行:每行包含两个整数i和j,表示学生i和j信仰相同的宗教。学生编号从1到n。输入的最后一行中,n = m = 0。Ou
2015-10-28 23:51:45 431
原创 并查集--POJ - 1611 The Suspects
Description严重急性呼吸系统综合症( SARS), 一种原因不明的非典型性肺炎,从2003年3月中旬开始被认为是全球威胁。为了减少传播给别人的机会, 最好的策略是隔离可能的患者。在Not-Spreading-Your-Sickness大学( NSYSU), 有许多学生团体。同一组的学生经常彼此相通,一个学生可以同时加入几个小组。为了防止非典的传播,NSYSU收集了所有学生团体
2015-10-28 00:24:34 565
原创 精华--CentOS多网卡配置
事情是这样的,我之前在windows用vmware建了一个centos,现在ubuntu开发,要用到之前的虚拟机,所以下了个vmware10, 因为文件格式来自于同一款软件,所以ubuntu下可以使用windows创建的虚拟机。顺利开机让我略感兴奋,当我配置完ssh后发现ip地址变了,然后我决定配置为静态的ip,重启网络时报错:没有找到合适的设备,没有找到可用于连接‘Auto_eth0'的设备
2015-10-26 10:00:58 2003
原创 Linux回收站管理
linux下的回收站在每一个当前用户目录./local/share/Trash中 ($HOME/.local/share/Trash/files/*)也可以给linux添加一个回收站。1、mkdir /tmp/trash_tmp 建立一个回收站目录2、vi /bin/trash 编辑一个文件#!/bin/shmv $@ /tmp/trash_tmp:wq 保存退出3、
2015-10-26 08:23:11 1086
原创 详解Linux中SSH远程访问控制
SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能(使用TCP的22号端口)。SSH协议对通信双方的数据传输进行了加密处理,其中包括用户登录时输入的用户口令。在RHEL 5系统中使用的是OpenSSH服务器由openssh,openssh-server等软件包提供的(默认已经安装),并以将sshd添加为标准的系统服务。推荐阅读:通过配置SSH深刻理解
2015-10-25 23:34:44 893
原创 Ubuntu软件安装卸载查看方法
说明:由于图形化界面方法(如Add/Remove... 和Synaptic Package Manageer)比较简单,所以这里主要总结在终端通过命令行方式进行的软件包安装、卸载和删除的方法。一、Ubuntu中软件安装方法1、APT方式(1)普通安装:apt-get install softname1 softname2 …;(2)修复安装:apt-get -f i
2015-10-25 17:31:11 638
原创 UVA - 140 Bandwidth
DescriptionGiven a graph (V,E) where V is a set of nodes and E is a set of arcs in VxV, and an ordering on the elements in V, then the bandwidth of a node v is defined as the maximum distance
2015-10-25 12:23:00 384
原创 UVA - 129 Krypton Factor
DescriptionYou have been employed by the organisers of a Super Krypton Factor Contest in which contestants have very high mental and physical abilities. In one section of the contest the conte
2015-10-24 21:16:51 485
原创 regular polygon can be drawn only by straightedge and compass
DescriptionYour task is to judge whether a regular polygon can be drawn only by straightedge and compass.The length of the straightedge is infinite.The width of the compass is infinite.The s
2015-10-24 18:53:58 421
统计学习方法 (李航)
2017-04-15
机器学习实战(英文+中文PDF+源码)
2017-04-15
PEview.exe
2016-04-08
修复windows7系统主题
2015-07-31
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人