- 博客(33)
- 收藏
- 关注
转载 树形dp mark
A - Anniversary partyHDU - 1520 题意是 有一个树 每个点都有一个价值,选了父亲节点就不能选子节点 选了子节点就不能选父亲节点 问最后能得到的最大价值是多少 树形dp入门 定义状态 dp[i][1]表示选中此节点 dp[i][0]表示未选中此节点 那么 dp[i][1]=sigma(dp[j][0])+a[i]; //j为i的儿子节点 ...
2017-08-17 09:17:00
161
转载 51nod 贪心系列
贴代码 水题 1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e4+4; 4 int ans; 5 int cnt[27]; 6 int main() 7 { 8 char c; 9 while(~scanf("%c",&c...
2017-08-16 16:50:00
159
转载 51nod level-5 系列
2017-8-15 题目思路:满足 gcd(x,n)==d 的x的数量即是 最大公约数d的贡献度,那么 gcd(x,n)==d 的数量 等价于 gcd(x/d,n/d)==1的数量 , 即为欧拉函数因此,我们枚举n所有的因子i,求一个euler(n/i) 即为gcd==i的数量,又由于这里 n是1e9范围 , 因子都是成对出现的 因此可以枚举因子到根号n即...
2017-08-15 23:36:00
169
转载 [kuangbin] 基础dp 2017-8-14
G - -免费馅饼 hdu1176 定义dp[t][x] 在t时刻位于坐标x,那么 dp[t][x]=max(dp[t-1][x-1],dp[t+1][x+1])+a[t][x]; 1 #include<bits/stdc++.h> 2 using namespace std; 3 int n; 4 int dp[100100]...
2017-08-14 10:23:00
159
转载 51nod 动态规划
1050循环数组最大子段和 基准时间限制:1秒 空间限制:131072KB 分值:10难度:2级算法题 收藏 关注 N个整数组成的循环序列a[1],a[2],a[3],…,a[n],求该序列如a[i]+a[i+1]+…+a[j]的连续的子段和的最大值(循环序列是指n个数围成一个圈,因此需要考虑a[n-1],a[n],a[1],a[2]...
2017-08-14 10:17:00
150
转载 2017-7-17/18 背包dp cf round 417 div2
poj3624 0-1背包 裸 1 #include<iostream> 2 #include<cstdio> 3 4 using namespace std; 5 const int maxn=15000; 6 int w[maxn]; 7 int v[maxn]; 8 int cost; 9 int main...
2017-07-17 16:36:00
167
转载 poj3667-Hotel-线段树-区间合并
Hotel Time Limit:3000MS Memory Limit:65536K Total Submissions:17533 Accepted:7588 Description The cows are journeying north to Thunder Bay in Canada to gain ...
2017-06-07 21:49:00
130
转载 STL 总结
发现stl还是很好用的。。。。学过以后,po一发博客便于以后复习和加深记忆和理解 首先对迭代器加以说明 C++ primer (中文版第四版)第273页 9.3.2 begin和end成员 begin和end操作产生指向容器内第一个元素和最后一个元素的下一个位置的迭代器,如下所示。这两个迭代器通常用于标记包含容器中所有元素的迭代范围。 c.begi...
2016-12-08 01:07:00
225
转载 c++ 用freopen简单的重定向,再也不怕debug了~
#define debug //去掉此句话,重定向部分失效 #include<iostream> #include<cstdio> using namespace std; int main() { #ifdef debug freopen("D:\\in.txt","r",stdin); //从in.txt文件输入 ...
2016-11-29 00:36:00
240
转载 dynamic programming 从入门到放弃
1. maxsum 最大连续子序列和 用d[i]表示以i结束的子序列和的最大值,状态转移方程为 d[i]=max{d[i-1]+a[i],a[i]},其中d[0]=a[0],然后对d[i] sort 取最大值 #include<iostream> #include<cstdio> #include<algorithm> #in...
2016-09-24 14:36:00
106
转载 sscanf()函数
C语言函数sscanf()的用法sscanf() - 从一个字符串中读进与指定格式相符的数据. 函数原型: int sscanf( string str, string fmt, mixed var1, mixed var2 ... ); int scanf( const char *format [,argument]... ); 说明: sscanf与scanf类似,都是用...
2016-09-18 17:30:00
127
转载 poj-1200-hash-
Crazy Search Time Limit:1000MS Memory Limit:65536K Total Submissions:27602 Accepted:7711 Description Many people like to solve hard puzzles some of which may l...
2016-09-18 14:04:00
107
转载 hduoj-1735 简单的贪心算法
字数统计 Time Limit: 1000/2000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1987Accepted Submission(s): 552 Problem Description 一天,淘气的Tom不小心将水泼到了他哥哥Jerry...
2016-09-12 21:46:00
226
转载 hduoj -2570-简单的贪心算法入门
迷瘴 Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 6739Accepted Submission(s): 2272 Problem Description 通过悬崖的yifenfei,又面临着幽谷的考验——幽谷周...
2016-09-12 19:26:00
213
转载 分治算法应用-最近点对的最小距离-hdu 1007 Quoit Design
题目描述 给出二维平面上的n个点,求其中最近的两个点的距离的一半。 输入包含多组数据,每组数据第一行为n,表示点的个数;接下来n行,每行一个点的坐标。当n为0时表示输入结束,每组数据输出一行,为最近的两个点的距离的一半。 输入样例: 2 0 0 1 1 2 1 1 1 1 3 -1.5 0 ...
2016-08-31 19:08:00
272
转载 分治算法(转载)
一、基本概念 在计算机科学中,分治法是一种很重要的算法。字面上的解释是“分而治之”,就是把一个复杂的问题分成两个或更多的相同或相似的子问题,再把子问题分成更小的子问题……直到最后子问题可以简单的直接求解,原问题的解即子问题的解的合并。这个技巧是很多高效算法的基础,如排序算法(快速排序,归并排序),傅立叶变换(快速傅立叶变换)…… 任何一个可以用计算机求解的问题所需的计算...
2016-08-31 16:00:00
121
转载 快速幂总结
求m^n%k的快速幂模板如下: int quickpow(int m,int n,int k) { int b=1; while(n>0) { if(n&1) b=(b*m)%k; n=n>>1; m=(m*m)%k; } return b; } ...
2016-08-31 15:47:00
91
转载 poj 1065 贪心算法
Wooden Sticks Time Limit:1000MS Memory Limit:10000K Total Submissions:21899 Accepted:9350 Description There is a pile of n wooden sticks. The length and weight...
2016-08-30 23:31:00
185
转载 toj ~3988~递归二叉树三种遍历的转换
3988.PasswordTime Limit:1.0 Seconds Memory Limit:65536KTotal Runs:476 Accepted Runs:200 Bob will get a bag as gift from Alice, but Alice don't wanna Bob get the bag without did an...
2016-08-30 17:23:00
136
转载 poj1664~递归
放苹果 Time Limit:1000MS Memory Limit:10000K Total Submissions:30797 Accepted:19444 Description 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法...
2016-08-15 00:00:00
108
转载 杭电oj~1228 map=_=
A + B Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15387Accepted Submission(s): 9162 Problem Description 读入两个小于100的正整数A和B,计算A+B.需...
2016-08-08 15:11:00
133
转载 杭电 oj2546~0-1背包问题
饭卡 Time Limit: 5000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22962Accepted Submission(s): 8047 Problem Description 电子科大本部食堂的饭卡有一种很诡异的设计,即在购买之前...
2016-08-06 23:36:00
252
转载 杭电 oj2602~(0-1背包问题)
Bone Collector Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 51417Accepted Submission(s): 21634 Problem Description Many years ago...
2016-08-06 21:41:00
189
转载 杭电oj~1005 简单的找周期
Number Sequence Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 153132Accepted Submission(s): 37335 Problem Description A number seq...
2016-08-01 22:21:00
128
转载 poj 2524~并查集基础
Ubiquitous Religions Time Limit:5000MS Memory Limit:65536K Total Submissions:31746 Accepted:15391 Description There are so many different religions in the worl...
2016-07-31 16:26:00
90
转载 poj 1611~并查集基础
The Suspects Time Limit:1000MS Memory Limit:20000K Total Submissions:33160 Accepted:16080 Description Severe acute respiratory syndrome (SARS), an atypical pne...
2016-07-31 15:50:00
101
转载 poj1182~食物链~带权并查集
食物链 Time Limit:1000MS Memory Limit:10000K Total Submissions:63050 Accepted:18482 Description 动物王国中有三类动物A,B,C,这三类动物的食物链构成了有趣的环形。A吃B, B吃C,C吃A。现有N个动物,以1-N编号。每个动物...
2016-07-30 23:33:00
89
转载 杭电 oj3047~带权并查集
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2947Accepted Submission(s): 1132 Problem Description In 12th Zhejiang C...
2016-07-30 15:51:00
132
转载 杭电 oj1232~并查集
畅通工程 Time Limit: 4000/2000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46491Accepted Submission(s): 24734 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表...
2016-07-28 22:06:00
102
转载 杭电 oj2033~
人见人爱A+B Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 37933Accepted Submission(s): 25228 Problem Description HDOJ上面已经有10来道A+B的题目了,...
2016-07-27 20:43:00
121
转载 杭电 oj2035~
#include<bits/stdc++.h> using namespace std; int quickpow(int m,int n,int k) { int ans=1; while(n>0) { if(n&1) ans=(ans*m)%k; m=(...
2016-07-27 20:09:00
241
转载 杭电 oj1097
#include<iostream> #include<cstdio> using namespace std; long long int quickpow(long long int m,int n,int k) { long long int ans=1; while(n>0) { if(n...
2016-07-27 20:01:00
314
转载 杭电oj 1020~
#include<bits/stdc++.h> #include<map> using namespace std; int main() { int n; while(~scanf("%d",&n)) { while(n--) { char...
2016-07-20 21:55:00
185
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅