自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

Yerkeys的博客

望图灵大爷赏口饭吃

  • 博客(63)
  • 收藏
  • 关注

原创 背包问题

01背包问题有n件物品,每件物品的重量为w[i],价值为c[i]。现有一个容量为V的背包,问如何选取物品放入背包,使得背包内物品总价值最大。其中每种物品只有一件。令dp[i][v]表示前i件物品恰好装入容量为v的背包所能获得的最大价值。考虑对第i件物品的选择:①不放第i件物品,则问题转化为前i-1件物品恰好装入容量为v的背包中所能获得的最大价值,即dp[i-1][v];②放第i件物...

2020-03-26 20:25:42 247

原创 PAT 1068 Find More Coins 01背包

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...

2020-03-26 19:47:38 180

原创 PAT 1007最大子序列和 1045最长不下降子序列 1040最长回文子串

1007Maximum Subsequence Sumdp[i]记录以A[i]结尾的最大连续子序列和,s[i]记录该序列对应的起始位置。状态转移方程:dp[i]=max(A[i],dp[i-1]+A[i])import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamRead...

2020-03-25 22:02:58 167

原创 PAT 1048 Find Coins 散列/双指针

Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...

2020-03-17 22:44:40 101

原创 PAT 1089 Insert or Merge

According to Wikipedia:Insertion sortiterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from the input data,...

2020-03-17 22:09:50 98

原创 PAT A 1029 Median 双指针/二分

Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1 = { 11, 12, 13, 14 } is 12, and the median of S2 = { 9, 10, 15, 16, 17 } is...

2020-03-17 21:03:01 145

原创 PAT 1010 Radix 二分

Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer isyes, if 6 is a decimal number and 110 is a binary number.Now for any pair of positive inte...

2020-03-16 14:51:42 114

原创 PAT A1085 Perfect Sequence / B1030 完美数列 二分/双指针

给定一个正整数数列,和正整数p,设这个数列中的最大值是M,最小值是m,如果M≤mp,则称这个数列是完美数列。现在给定参数p和一些正整数,请你从中选择尽可能多的数构成一个完美数列。输入格式:输入第一行给出两个正整数N和p,其中N(≤10​5​​)是输入的正整数的个数,p(≤10​9​​)是给定的参数。第二行给出N个正整数,每个数不超过10​9​​。输出格式:...

2020-03-15 23:49:07 145

原创 PAT 1038 Recover the Smallest Number 贪心

Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we can recover many numbers such like 32-321-3214-0229...

2020-03-15 22:53:14 117

原创 PAT 1033 To Fill or Not to Fill 贪心

With highways available, driving a car from Hangzhou to any other city is easy. But since the tank capacity of a car is limited, we have to find gas stations on the way from time to time. Different ga...

2020-03-14 22:41:04 163

原创 PAT 1084 Broken Keyboard 散列

On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to...

2020-03-13 23:33:20 98

原创 PAT 1016 Phone Bills 排序

A long-distance telephone company charges its customers by the following rules:Making a long-distance call costs a certain amount per minute, depending on the time of day when the call is made. When...

2020-03-13 21:20:58 95

原创 PAT 甲级1012 The Best Rank 排序

To evaluate the performance of our first year CS majored students, we consider their grades of three courses only:C- C Programming Language,M- Mathematics (Calculus or Linear Algrbra), andE- Eng...

2020-03-13 14:20:26 131

原创 PAT 甲级 1062 Talent and Virtue 排序

About 900 years ago, a Chinese philosopher Sima Guang wrote a history book in which he talked about people's talent and virtue. According to his theory, a man being outstanding in both talent and virt...

2020-03-13 12:15:28 241

原创 PAT 甲级 1025 PAT Ranking 排序

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists w...

2020-03-11 18:26:04 117

原创 素数算法

1、素数判定给定整数n,判断n是不是素数。0<n<=10^9n除了本身,所有的约数都不大根号n,算法复杂度为O(√n) //素数判定 bool is_prime(int n){ for(int i=2;i*i<=n;i++) if(n%i==0) return false; return n!=1;}//枚举n所有的约数 vector<i...

2019-02-21 21:18:53 331

原创 POJ2686 Traveling by Stagecoach 状态压缩DP

DescriptionOnce upon a time, there was a traveler. He plans to travel using stagecoaches (horse wagons). His starting point and destination are fixed, but he cannot determine his route. Your job in...

2019-02-20 15:33:22 162

原创 POJ1837 Balance 01背包

DescriptionGigel has a strange "balance" and he wants to poise it. Actually, the device is different from any other ordinary balance. It orders two arms of negligible weight and each arm's length i...

2019-02-17 22:02:18 122

原创 POJ1416 Shredding Company深搜

Description题干  InputThe input consists of several test cases, each on one line, as follows : tl num1 t2 num2 ... tn numn 0 0 Each test case consists of the following two positive intege...

2019-02-02 20:20:47 241

原创 POJ1426 Find The Multiple 深搜/广搜

DescriptionGiven a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assume that n is not greater than ...

2019-02-02 13:49:13 147

原创 POJ2482 Stars in Your Window

Description(一段令人感动的程序员的爱情故事...)Here comes the problem: Assume the sky is a flat plane. All the stars lie on it with a location (x, y). for each star, there is a grade ranging from 1 to 100, rep...

2019-01-31 22:24:58 216

原创 POJ1001 Exponentiation 高精度

求高精度幂Description对数值很大、精度很高的数进行高精度计算是一类十分常见的问题。比如,对国债进行计算就是属于这类问题。 现在要你解决的问题是:对一个实数R( 0.0 < R < 99.999 ),要求写程序精确计算 R 的 n 次方(Rn),其中n 是整数并且 0 < n <= 25。InputT输入包括多组 R 和 n。 R 的值占第 1 到...

2019-01-30 22:33:39 179

原创 POJ2488 Knight's Journey 深搜DFS

A Knight's Journey DescriptionBackground The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a k...

2019-01-23 19:08:08 150

原创 POJ2386 Lake Counting 深度优先搜索

poj2386DescriptionDue to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. E...

2019-01-22 14:23:48 159

原创 POJ 1151 Atlantis 线段树+离散化+扫描线

DescriptionThere are several ancient Greek texts that contain descriptions of the fabled island Atlantis. Some of these texts even include maps of parts of the island. But unfortunately, these maps ...

2019-01-12 19:30:14 223 1

原创 欧几里得算法及扩展

辗转相除法求整数a,b的最大公约数gcd(a,b):定理:gcd(a,b)=gcd(b,a%b)证明:设a除以b得到的商和余数分别为k和r,则a=kb+r,r=a%b,设d为a,b公约数,则d一定整除r=a-kb,所以d是(b,a%b)的公约数。(a,b)和(b,a %b)公约数相同,最大公约数也一定相等。根据该定理不断操作下去最终得到gcd(a,b)=gcd(c,0)=c。复杂度...

2018-03-31 12:36:47 211 1

原创 POJ1144 Network 割点

NetworkDescriptionA Telephone Line Company (TLC) is establishing a new telephone cable network. They are connecting several places numbered by integers from 1 to N . No two places have the same number...

2018-03-27 21:58:41 200

原创 POJ3177 Redundant Paths边双连通分量

http://poj.org/problem?id=3177题意:有F个牧场(1<=F<=5000),现在一个牧群经常需要从一个牧场迁移到另一个牧场。奶牛们已经厌烦老是走同一条路,所以有必要再新修几条路,这样它们从一个牧场迁移到另一个牧场时总是可以选择至少两条独立的路。现在F个牧场的任何两个牧场之间已经至少有一条路了,奶牛们需要至少有两条。给定现有的R条(F-1<=R<=1...

2018-03-25 15:44:34 210

原创 POJ2186 Popular Cows 强连通分量tarjan算法

http://poj.org/problem?id=2186题意:n头奶牛给出m组欢迎关系 a,b 表示a欢迎b,欢迎关系时单向、传递的,求出被所有的奶牛欢迎的奶牛的数目。分析:可将题目转换为N个顶点M条边的有向图,求有多少点可以由其余任意点到达。如果图为树,则至多有1个点满足条件,这个点一定是树中唯一的出度为0的点。用Tarjan算法求出图中所有的极大强连通分量将其缩成点,图就可以转换为树。求树...

2018-03-24 18:39:14 165

原创 POJ 1679 The Unique MST 次小生成树

http://poj.org/problem?id=1679题意:给出N个点和M条边,判断最小生成树是否唯一。分析:次小生成树基本的思想就是连入一条不在最小生成树上的边,从而形成一个环,去掉在环中并且在最小生成树上最大的边计算权值,遍历所有不在最小生成树上的边并进行同样的操作最小值即为次小生成树。prime算法:先求出最小生成树,并用数组Max[i][j]记录生成树上任意两点间权值最大的边的权值,...

2018-03-22 20:40:41 129

原创 蓝桥杯 垒骰子 矩阵快速幂

赌圣atm晚年迷恋上了垒骰子,就是把骰子一个垒在另一个上边,不能歪歪扭扭,要垒成方柱体。经过长期观察,atm 发现了稳定骰子的奥秘:有些数字的面贴着会互相排斥!我们先来规范一下骰子:1 的对面是 4,2 的对面是 5,3 的对面是 6。假设有 m 组互斥现象,每组中的那两个数字的面紧贴在一起,骰子就不能稳定的垒起来。 atm想计算一下有多少种不同的可能的垒骰子方式。两种垒骰子方式相同,当...

2018-03-17 20:27:43 283

原创 POJ3735 Training little cats 矩阵快速幂

DescriptionFacer's pet cat just gave birth to a brood of little cats. Having considered the health of those lovely cats, Facer decides to make the cats to do some exercises. Facer has well designed ...

2018-03-17 19:02:11 174

原创 快速幂运算

1.乘方取模问题:给定正整数x,n,m,计算x^n(mod m)。最简单代码,复杂度为O(n):ll res=1;for(int i=0;i<n;i++){    res=res*x%m;}2、快速幂,将n表示为2的幂次的和:,可以将x^n转化为:,依次由n的二进制位求x^2ki即可,复杂度降为O(logn)。例如,x^23=x^16*x^4*x^2*x(23二进制...

2018-03-17 18:42:57 208

原创 蓝桥杯 生命之树 树形DP

生命之树在X森林里,上帝创建了生命之树。他给每棵树的每个节点(叶子也称为一个节点)上,都标了一个整数,代表这个点的和谐值。上帝要在这棵树内选出一个非空节点集S,使得对于S中的任意两个点a,b,都存在一个点列 {a, v1, v2, ..., vk, b} 使得这个点列中的每个点都是S里面的元素,且序列中相邻两个点间有一条边相连。在这个前提下,上帝要使得S中的点所对应的整数的和尽...

2018-03-16 23:36:31 553

原创 HDU 2196 Computer 树形DP

DescriptionA school bought the first computer some time ago(so this computer's id is 1). During the recent years the school bought N-1 new computers. Each new computer was connected to one of settle...

2018-03-14 23:01:05 144

原创 POJ 2485 Highways Kruskal最小生成树

DescriptionThe island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public highways. So the traffic is difficult in Flatopia. The Flatopian government is aware of this problem...

2018-03-13 23:02:08 150

原创 POJ1258 Agri-Net 最小生成树Prim

DescriptionFarmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course.Farmer John order...

2018-03-13 21:59:52 184

原创 POJ 1463 Strategic game 树形DP

DescriptionBob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must def...

2018-03-11 21:59:04 172

原创 HDU1520 Anniversary party 树形dp

DescriptionThere is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The University has a hierarchical structure of employees. It means that the supervisor relati...

2018-03-11 21:04:10 110

原创 POJ1125 Stockbroker Grapevine 多源最短路径Floyd

http://poj.org/problem?id=1125题意:股票经纪人要在一群人中散布传言,传言只能在认识的人中传递。给出经纪人的人数,每个经纪人和其他人关系的信息:编号和传递时间,求出以哪个人为起点可以在耗时最短的情况下让所有收到消息。分析:多源最短路径问题,求出每个人传播消息给其他人的最短路径中的最大时间,从所有最大时间中找出最小值。#include<iostr...

2018-03-11 16:41:53 337

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除