随笔分类 -  动态规划DP

1

摘要:http://poj.org/problem?id=3132题意就是要求一个数可以分解成指定数个素数的和的种数方法是参考网上的大牛的做法,学习了!Sum of Different PrimesTime Limit:5000MSMemory Limit:65536KDescriptionA positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integersnandk, you should count t 阅读全文

posted @ 2011-01-23 19:19 yming0221 阅读(157) 评论(0) 推荐(0)

摘要:http://poj.org/problem?id=3670Eating TogetherTime Limit:1000MSMemory Limit:65536KDescriptionThe cows are so very silly about their dinner partners. They have organized themselves into three groups (conveniently numbered 1, 2, and 3) that insist upon dining together. The trouble starts when they line 阅读全文

posted @ 2011-01-21 19:36 yming0221 阅读(172) 评论(0) 推荐(0)

摘要:http://poj.org/problem?id=3671简单动态规划opt[i][0]第i个数后1的个数;opt[i][1] 第i个数前2的个数状态方程opt[i][0]=opt[i-1][0]-1 //value[i]=1opt[i][0]=opt[i-1][0] //value[i]=2opt[i][1]=opt[i-1][1] //value[i-1]=1opt[i][1]=opt[i-1][1]+1 //value[i-1]=2 Dining CowsTime Limit:1000MSMemory Limit:65536KDescriptionThe cows ... 阅读全文

posted @ 2011-01-20 14:03 yming0221 阅读(281) 评论(0) 推荐(0)

摘要:http://poj.org/problem?id=2250最长公共子序列LCS 动态规划DPCompromiseTime Limit:1000MS Memory Limit:65536KSpecial JudgeDescriptionIn a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countr 阅读全文

posted @ 2011-01-05 14:32 yming0221 阅读(130) 评论(0) 推荐(0)

摘要:本题就是求一个数是否能写成几个数的阶乘的和的形式,可以当作背包问题,也可以用DFS来解,下面用的贪心http://poj.org/problem?id=1775Sum of FactorialsTime Limit:1000MSMemory Limit:30000KDescriptionJohn von Neumann, b. Dec. 28, 1903, d. Feb. 8, 1957, was a Hungarian-American mathematician who made important contributions to the foundations of mathemati 阅读全文

posted @ 2010-12-23 13:38 yming0221 阅读(231) 评论(0) 推荐(0)

摘要:刚刚看到我还以为是就是简单排序呢,总是WA然后又使用二进制枚举,不过二进制还不太熟悉,用的将十进制计算转换成二进制,然后计算,总是TLE,记录一下,练习练习位操作最后看到了递归的方法当然本题属于背包问题,可以用DP解决标记,学习了!/* Author : yan * Question : POJ 3628 Bookshelf 2 * Data && Time : Wednesday, December 22 2010 11:34 PM*/#include<stdio.h>int cow[20];int b;int n;int ans=99999999;void DF 阅读全文

posted @ 2010-12-23 07:20 yming0221 阅读(158) 评论(0) 推荐(0)

摘要:一看到该题就认为可以用最长公共子序列来解于是写了一下,提交显示MLE,改成循环数组又WA,不知道哪里问题看到别人的解法,感觉思维方式很特别,很好,循环长串指针,比较长串和短串的一位,如果相等,短串指针加一最后判断一下短串的指针有没有指到最后,如果移动到最后就说明查长串包含短串,否则.....也提醒一下自己的思维定势All in AllTime Limit:1000MSMemory Limit:30000KTotal Submissions:17955Accepted:7127DescriptionYou have devised a new encryption technique which 阅读全文

posted @ 2010-12-18 20:09 yming0221 阅读(115) 评论(0) 推荐(0)

摘要:本题就是求最长递增子序列的长度,用动态规划Bridging signalsTime Limit:1000MSMemory Limit:10000KDescription'Oh no, they've done it again', cries the chief designer at the Waferland chip factory. Once more the routing designers have screwed up completely, making the signals on the chip connecting the ports of t 阅读全文

posted @ 2010-12-16 11:32 yming0221 阅读(152) 评论(0) 推荐(0)

摘要:POJ 1496 Word IndexTime Limit:1000MSMemory Limit:10000KTotal Submissions:3035Accepted:1731DescriptionEncoding schemes are often used in situations requiring encryption or information storage/transmission economy. Here, we develop a simple encoding scheme that encodes particular types of words with f 阅读全文

posted @ 2010-12-13 13:14 yming0221 阅读(211) 评论(0) 推荐(0)

摘要:Jumping CowsTime Limit:1000MSMemory Limit:65536KTotal Submissions:4477Accepted:2705DescriptionFarmer John's cows would like to jump over the moon, just like the cows in their favorite nursery rhyme. Unfortunately, cows can not jump.The local witch doctor has mixed up P (1 <= P <= 150,000) 阅读全文

posted @ 2010-12-09 11:12 yming0221 阅读(137) 评论(0) 推荐(0)

摘要:本题就是让你输出N位的二进制数中不包含两个连续的1的个数DP瞬秒!!!关键是找到DP方程假设二进制序列为a1,a2,a3,........a(i-2),a(i-1),a(i)opt[i]表示i位二进制数中符合上述特性的数字个数则可得到opt[i]=opt[i-1]+opt[i-2]因为,如果a(i)为0,则,opt[i]=opt[i-1]如果a(i)为1,那么a(i-1)一定为0,则,opt[i]=opt[i-2]动态规划的题目关键就是找到合适的状态转移方程#include<stdio.h>int opt[50];int binary[10];void decimal_to_bin 阅读全文

posted @ 2010-12-07 15:22 yming0221 阅读(145) 评论(0) 推荐(0)

摘要:标记有空好好研究 阅读全文

posted @ 2010-12-03 22:14 yming0221 阅读(90) 评论(0) 推荐(0)

摘要:Tight wordsTime Limit: 1000MSMemory Limit: 65536KTotal Submissions: 2079Accepted: 1041DescriptionGiven is an alphabet {0, 1, ... , k}, 0 <= k <= 9 . We say that a word of length n over this alphabet is tight if any two neighbour digits in the word do not differ by more than 1. InputInput is a 阅读全文

posted @ 2010-12-03 08:57 yming0221 阅读(199) 评论(0) 推荐(0)

摘要:Charm BraceletTime Limit:1000MSMemory Limit:65536KTotal Submissions:6996Accepted:3174DescriptionBessie has gone to the mall's jewelry store and spies a charm bracelet. Of course, she'd like to fill it with the best charms possible from theN(1 ≤N≤ 3,402) available charms. Each charmiin the su 阅读全文

posted @ 2010-12-01 22:13 yming0221 阅读(124) 评论(0) 推荐(0)

摘要:动态规划经典为题给出不同的砝码,可以悬挂在天平的不同位置,求出可以保持天平平衡的悬挂种数BalanceTime Limit:1000MSMemory Limit:30000KTotal Submissions:4309Accepted:2521DescriptionGigel 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 we 阅读全文

posted @ 2010-12-01 13:46 yming0221 阅读(265) 评论(0) 推荐(0)

摘要:经典动态规划现在对动态规划的子结构划分和子结构的理解,转移方程还没有明确的认识ZipperTime Limit:1000MSMemory Limit:65536KTotal Submissions:9409Accepted:3218DescriptionGiven three strings, you are to determine whether the third string can be formed by combining the characters in the first two strings. The first two strings can be mixed arb 阅读全文

posted @ 2010-12-01 12:46 yming0221 阅读(173) 评论(0) 推荐(0)

摘要:每组给出两个字符串,输入以EOF结束,只输出公共子序列的最大长度第一次数组开100 RE,改成200后 AC!#include<stdio.h>#define MAX 200int opt[MAX][MAX];char str1[MAX],str2[MAX];int main(){ int str1_len,str2_len; int i,j; //freopen("input","r",stdin); while(scanf("%s %s",str1,str2)!=EOF) { str1_len=strlen(str1) 阅读全文

posted @ 2010-11-29 18:26 yming0221 阅读(160) 评论(0) 推荐(0)

摘要://现在还有点不太明白,记录一下,慢慢体会Human Gene FunctionsTime Limit:1000MSMemory Limit:10000KTotal Submissions:10338Accepted:5718DescriptionIt is well known that a human gene can be considered as a sequence, consisting of four nucleotides, which are simply denoted by four letters, A, C, G, and T. Biologists have be 阅读全文

posted @ 2010-11-29 14:52 yming0221 阅读(248) 评论(0) 推荐(0)

摘要:CompromiseTime Limit:1000MSMemory Limit:65536KTotal Submissions:3300Accepted:1542Special JudgeDescriptionIn a few months the European Currency Union will become a reality. However, to join the club, the Maastricht criteria must be fulfilled, and this is not a trivial task for the countries (maybe ex 阅读全文

posted @ 2010-11-29 13:13 yming0221 阅读(127) 评论(0) 推荐(0)

摘要:http://zh.wikipedia.org/zh/%E5%8A%A8%E6%80%81%E8%A7%84%E5%88%92题目描述:依次从左到右给你n个数字,每次取出一个数字(这个数字不能是最两边的数字), 这个数字和它左右两边的数字(一共三个数字)相乘,累加这个数。直到最后仅剩下两个数字。求最后累加的最小值。分析:dp。 dp[i][j] 表示把第 i 个数字到第 j 个数字之间(不包括i,j)的数字去光后得到的最小值。设 x[i] 是第 i 个数字的值。dp[i][j] = min(dp[i][k] + dp[k][j] + x[i] * x[k] * x[j]),i + 1 < 阅读全文

posted @ 2010-11-21 20:40 yming0221 阅读(134) 评论(0) 推荐(0)

1

导航