2013年11月4日

Max Sum

摘要: hdu1003:http://acm.hdu.edu.cn/showproblem.php?pid=1003题意:给你n个数的序列,求一个连续最大的子序列的和。题解:简单的动态规划。从开始,选择一个连续和是递增的序列,如果当前这段和小于零.则从下一段开始,若下一段的和大于该段,则更新起点和终点。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int a[100020]; 7 int n,cas; 8 int main(){ 9 scanf("%d",&cas);10 int 阅读全文

posted @ 2013-11-04 18:39 天依蓝 阅读(156) 评论(0) 推荐(0) 编辑

2013年11月3日

Communication System

摘要: poj1018:http://poj.org/problem?id=1018题意:某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产,而每个厂家生产的同种设备都会存在两个方面的差别:带宽bandwidths 和 价格prices。现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。其中B为这n件设备的带宽的最小值,P为这n件设备的总价。题解:方法一:暴力枚举。枚举每个bandwidth,然后从剩余的n-1个类中,找出bandwith大于等于这个ban的width而且price最小的那个值,然后求 阅读全文

posted @ 2013-11-03 20:29 天依蓝 阅读(261) 评论(0) 推荐(0) 编辑

2013年11月1日

Dollars

摘要: uva147:题意:给你几种钱币,在给你一个钱的数目,问有多少种用这些钱来组成这个数目。题解:完全背包,不过此时要把钱的数目*100,因为是小数,背包的容量都是整数,然后dp,求出每个容量的数目即可 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 int we[13]; 8 long long dp[30003]; 9 int main(){10 we[1]=5;we[2]=10;we[3]=20;we[4]=50;we[5]=100;11 we[6]=200;we... 阅读全文

posted @ 2013-11-01 16:12 天依蓝 阅读(217) 评论(0) 推荐(0) 编辑

Coin Change

摘要: uva674:题意:有1,5,10,25,50这五种硬币。给一个价值,求有多少种组合可以得到该价值。题解:完全背包 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int we[6]; 7 int dp[7499]; 8 int main(){ 9 we[1]=1;we[2]=5;we[3]=10;we[4]=25;we[5]=50;10 int n;11 12 memset(dp,0,sizeof(dp));13 dp[0]=1;14 ... 阅读全文

posted @ 2013-11-01 16:04 天依蓝 阅读(266) 评论(1) 推荐(0) 编辑

GCD - Extreme (II)

摘要: uva11424:题目:给出n,求gcd(1,2)+gcd(1,3)+gcd(2,3)+gcd(1,4)+gcd(2,4)+gcd(3,4)+...+gcd(1,n)+gcd(2,n)+...+gcd(n-1,n) 此题和UVA 11426 一样,不过n的范围只有20000,但是最多有20000组数据。 当初我直接照搬UVA11426,结果超时,因为没有预处理所有的结果(那题n最多4000005,但最多只有100组数据),该题数据太多了额。。。思路:令sum(n)=gcd(1,n)+gcd(2,n)+...+gcd(n-1,n),则所求结果ans(n)=sum(2)+sum(3)+...+s. 阅读全文

posted @ 2013-11-01 16:00 天依蓝 阅读(619) 评论(0) 推荐(0) 编辑

Sliding Window

摘要: poj2823:http://poj.org/problem?id=2823题意:给出一个序列,要求得到所有长度为k的连续子序列的最大和最小值。题解:直接上线段树 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 const int maxn=1000002; 7 int n,k,s; 8 struct Node{ 9 int left;10 int right;11 int minn;12 int maxn;13 }node[4*maxn];14 void build(... 阅读全文

posted @ 2013-11-01 15:55 天依蓝 阅读(247) 评论(0) 推荐(0) 编辑

Cow Exhibition

摘要: poj2184:http://poj.org/problem?id=2184题意:给你n头牛,每头牛有一个S值和一个F值,现在的问题是,要你选出其中的一些牛求出S+T的最大值。但是要保证总的s>=0和F>=0 题解:可以把s作为体积,然后利用0,1背包。求出每个s做对应的最大的F值,然后for一遍,求出最大的f+s。因为有负的值出现,所以把 背包的容量加上一个100000;因为过程中s的值可以是小于0的,for的时候从100000开始即可,不是很好理解。 1 #include 2 #include 3 #include 4 #include 5 using namespace st 阅读全文

posted @ 2013-11-01 15:50 天依蓝 阅读(189) 评论(0) 推荐(0) 编辑

饭卡

摘要: hdu2546:http://acm.hdu.edu.cn/showproblem.php?pid=2546题意:给你N元,每一件食品可以购买一次,如果卡上多余5元即使透支也可以刷卡。少于5元不能使用,求最多能让卡的余额为多少? 题解:01背包问题,首先拿出5元买最贵的东西,那接下来就是背包容量m-5,物品数量n-1 的01背包问题了。 1 #include 2 #include 3 #include 4 #include 5 #include 6 #define N 1003 7 using namespace std; 8 int v[N],dp[N],n,k; 9 int main(v. 阅读全文

posted @ 2013-11-01 13:34 天依蓝 阅读(155) 评论(0) 推荐(0) 编辑

2013年10月27日

Catenyms

摘要: poj2337:http://poj.org/problem?id=2337题意:给定一些单词,如果一个单词的尾字母与另一个的首字母相同则可以连接。问是否可以每个单词用一次,将所有单词连接,可以则输出字典序最小的序列。 题解:并查集+欧拉通路+贪心思维+dfs ,这一题我也是参考了别人的代码。 ps:vector的使用 ,内部堆栈的使用 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 struct Node{ 9 int v; 10... 阅读全文

posted @ 2013-10-27 20:02 天依蓝 阅读(157) 评论(0) 推荐(0) 编辑

滑雪

摘要: poj1088:http://poj.org/problem?id=1088题意:给出矩阵地图,值为高度,找一条最长的高度递减的路径。题解:动态记忆递归搜索,在递归最底层求出最优解,记录,自底向上的方式求出最优解。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 int map[102][102],cnt[102][102]; 7 int sum,temp,n,m; 8 int DFS(int x,int y){ 9 int max1=0;10 if(cnt[x][y]>0){... 阅读全文

posted @ 2013-10-27 19:18 天依蓝 阅读(170) 评论(0) 推荐(0) 编辑

导航