poj 1088 記憶化搜尋||動態規劃

   poj 1088      記憶化搜尋也也是採用遞迴深搜的對資料進行搜尋,但不同於直接深搜的方式,記憶化搜尋是在每次搜尋時將得到的結果儲存下來,避免了重複計算,這就是所謂的記憶化。記憶化應該是屬於動態規劃。      舉個例子,比如我們搜尋最長最長連續增子序列, 1  2 3 4 5 6 7, 當然這個例子比較特殊,但足以說明情況。      對於這種問題,我們可以先搜尋以1開始的,定義一個函數dfs(1), 然後在dfs(1)中將第二個與一個數比較,如果大的話返回1+dfs(2)。。。。

此刻,Blog開始!

  不大好意思說出口,自打申請csdn帳號到現在,還沒有正兒八經的寫過一篇Blog。與大多數人一樣,沒話可寫應該是首要原因,其實不要刻意於寫的內容,寫作應該是一件愉快的事情,想寫就寫所以,有時間就動手吧,開個Blog,沒事多寫寫。 寫作有不少好處,這個在劉未鵬的 為什麼你應該(從現在開始就)寫部落格 一文中有詳細的說明,贊一個! 在劉的文章中描述了寫作的一些好處,這裡我比較贊同

單鏈表隊列

#include <stdio.h>#include <malloc.h>#include <stdlib.h>#define STACK_SIZE 100#define STACK_INCREASE 10#define OK -100#define ERROR -1//--------------------------------------------------------------------------typedef int QElemType;

歸併樹&劃分樹詳解

先放一張圖片對4 5 2 8 7 6 1 3 分別建劃分樹和歸併樹劃分樹如紅色的點是此節點中被劃分到左子樹的點。     

NYOJ 36 LCS 動態規劃入門

#include <stdio.h>#include <string.h>int max( int a, int b ){return a > b ? a : b;}int d[1001][1001];char s1[2000];char s2[2000];int main(){int la, lb, N;scanf( "%d", &N );while( N-- ){memset( d, 0, sizeof(d) );scanf( "%s", s1 );

codeforces 285C – Building Permutation

題目連結題目大意是有一個含n個數的數組,你可以通過+1或者-1的操作使得其中的數是1--n中的數,且沒有重複的數。既然是這樣的題意,那麼我就應該把原數組中的數盡量往他最接近1--n中的位置放,然後求差絕對值之和,但有多個數,怎麼使他們和最小,這樣就要對其進行排序了,直接按大小給它們安排好位置,然後計算。//CF 285C//2013-06-06-19.57#include <stdio.h>#include <stdlib.h>#include

NYOJ 18 動態規劃入門

#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>int d[1000][1000];int N;int max( int a, int b ){return a > b ? a: b;}int main(){scanf( "%d", &N );memset( d, 0, sizeof(d) );for( int i = 1; i

hdoj 1230 火星A+B

#include<stdio.h>#include<string.h>int a[150],b[150],t[150];int pr[150];void prime(){ int i, j, f, cnt = 1; pr[0] = 2; for(i = 3; ;i++) { f = 1; for(j = 2;j * j <= i; j++) { if(i % j == 0)

ZOJ 1242 ??

//半衰期log2 ?//代碼參考網上的,用到了換底公式#include <stdio.h>#include <stdlib.h>#include <math.h>int main(){ int w, d, cout = 1; int dec = 5730, result; double temp, year; while( scanf( "%d%d", &w, &d )!= EOF && w ) {

uva 993

一個數分解,不過是從2開始的,1 分解是 1   2分解是  2        3分解是    3        4 分解是 4   不清楚為什麼 10 分解不是10  而是 2 5題目說是找最小的Q 但是 10  不是比25 小嗎?

uva 644

第一次交用的冒泡排序,Re了, 改成快排OK#include <stdio.h>#include <string.h>#include <iostream>#include <cstdlib>using namespace std;char temp[100][10];int cmp( const void *_a, const void * _b ){ char * a = (char*)_a; char * b = (char*

codeforces 299 A. Ksusha and Array

題目連結題目就是讓你找出一個數組中可以將這個數組中所有數整除的數,很明顯,如果存在,這個數肯定是最小的一個。//cf 299A//2013-06-05-20.51#include <stdio.h>#include <string.h>#include <algorithm>using namespace std;const int maxn = 100005;int a[maxn];int main(){ int n; while (scanf(

uva 712

簡單的建立樹,遍曆 資料也很水1A的題#include <stdio.h>#include <string.h>#include <stdlib.h>#include <math.h>int time = 1, n;int tree[1000];int flag;void deal( int i ){if( flag == -1 )return ;if( i >= pow(2,n)-1 ){printf( "%d", tree[i]

poj 1159 Palindrome(最長公用子串)

大概題意就是求最少添加多少個字元可以把長度為N的字串編程迴文串。則需要最少需要補充的字母數 = 原序列S的長度 —  S和S'的最長公用子串長度S'為原串的逆串。關於求最長公用子串, 用到的是動態規劃虛擬碼如下if( i ==0 || j == 0 ) {       MaxLen(i, j) = 0 //兩個空串的最長公用子序列長度當然是0}else if( s1[i] == s2[j] )          MaxLen(i, j) = MaxLen(i-1, j-1 ) + 1;else

sicp 習題2.7 && 2.8

題目:(define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y))))和的最小值應該是兩個區間下界之和,和的最大值應該是兩個區間上界之和求出:  1.upper-bound 和 lower-bound的定義 2.定義 sub-interval 這是我的理解圖(define

最小產生樹prim演算法

#include <conio.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#define INFINITY 30000 //定義一個權值的最大值#define MAX_VERTEX_NUM 20 // 圖的最大頂點數 typedef struct{int arcs[MAX_VERTEX_NUM][MAX_VERTEX_NUM]; // 鄰接矩陣 int

POJ 1922 Ride to School

             智商,,,,,,訓練賽上的題目,注重思路的分析,看解題報告分析的特別好。    #include<cstdio>#include<cmath>using namespace std;int main(){ int vis,time,minn,min; int n; while(scanf("%d",&n)&&n) { int flag=0; for(int i=0; i&

uva 401

代碼寫得有點小繁瑣,見諒吧....懶得再算數組順序了#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; int is_palindrome( char str[] ); int is_mirrored( char str[] );

UVa 10129 Play on Words ( euler path )

歐拉路徑的問題。有向圖判定是否存在歐拉道路的步驟:判定連通,判定點的入度和出度的關係!首先,因為單詞的擺放是有方向的,所以要建一個有向圖。其中,要注意的是,很可能會有重邊出現,所以一定要做的一件事是記錄重邊的個數,因為在滿足圖去掉方向之後是連通的,那麼就看每個點入度和出度的關係就好;然後,判斷這個圖是否連通,如果不連通,可以肯定是沒有方案存在的;接下來是判斷一共有幾個點是入度和出度不等的,如果超過兩個點,就一定沒有歐拉道路存在;如果是2個點,要判定這個兩個點是不是一個是起點,一個是匯點,起點是出

UVA 10878

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int main(){ char str[20]; int i, key; while( fgets(str, 20, stdin ) ) { if( str[i] == '_' ) continue; key =

總頁數: 61357 1 .... 15173 15174 15175 15176 15177 .... 61357 Go to: 前往

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.