Time of Update: 2018-12-05
poj 1088 記憶化搜尋也也是採用遞迴深搜的對資料進行搜尋,但不同於直接深搜的方式,記憶化搜尋是在每次搜尋時將得到的結果儲存下來,避免了重複計算,這就是所謂的記憶化。記憶化應該是屬於動態規劃。 舉個例子,比如我們搜尋最長最長連續增子序列, 1 2 3 4 5 6 7, 當然這個例子比較特殊,但足以說明情況。 對於這種問題,我們可以先搜尋以1開始的,定義一個函數dfs(1), 然後在dfs(1)中將第二個與一個數比較,如果大的話返回1+dfs(2)。。。。
Time of Update: 2018-12-05
不大好意思說出口,自打申請csdn帳號到現在,還沒有正兒八經的寫過一篇Blog。與大多數人一樣,沒話可寫應該是首要原因,其實不要刻意於寫的內容,寫作應該是一件愉快的事情,想寫就寫所以,有時間就動手吧,開個Blog,沒事多寫寫。 寫作有不少好處,這個在劉未鵬的 為什麼你應該(從現在開始就)寫部落格 一文中有詳細的說明,贊一個! 在劉的文章中描述了寫作的一些好處,這裡我比較贊同
Time of Update: 2018-12-05
#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;
Time of Update: 2018-12-05
先放一張圖片對4 5 2 8 7 6 1 3 分別建劃分樹和歸併樹劃分樹如紅色的點是此節點中被劃分到左子樹的點。
Time of Update: 2018-12-05
#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 );
Time of Update: 2018-12-05
題目連結題目大意是有一個含n個數的數組,你可以通過+1或者-1的操作使得其中的數是1--n中的數,且沒有重複的數。既然是這樣的題意,那麼我就應該把原數組中的數盡量往他最接近1--n中的位置放,然後求差絕對值之和,但有多個數,怎麼使他們和最小,這樣就要對其進行排序了,直接按大小給它們安排好位置,然後計算。//CF 285C//2013-06-06-19.57#include <stdio.h>#include <stdlib.h>#include
Time of Update: 2018-12-05
#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
Time of Update: 2018-12-05
#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)
Time of Update: 2018-12-05
//半衰期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 ) {
Time of Update: 2018-12-05
一個數分解,不過是從2開始的,1 分解是 1 2分解是 2 3分解是 3 4 分解是 4 不清楚為什麼 10 分解不是10 而是 2 5題目說是找最小的Q 但是 10 不是比25 小嗎?
Time of Update: 2018-12-05
第一次交用的冒泡排序,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*
Time of Update: 2018-12-05
題目連結題目就是讓你找出一個數組中可以將這個數組中所有數整除的數,很明顯,如果存在,這個數肯定是最小的一個。//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(
Time of Update: 2018-12-05
簡單的建立樹,遍曆 資料也很水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]
Time of Update: 2018-12-05
大概題意就是求最少添加多少個字元可以把長度為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
Time of Update: 2018-12-05
題目:(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
Time of Update: 2018-12-05
#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
Time of Update: 2018-12-05
智商,,,,,,訓練賽上的題目,注重思路的分析,看解題報告分析的特別好。 #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&
Time of Update: 2018-12-05
代碼寫得有點小繁瑣,見諒吧....懶得再算數組順序了#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; int is_palindrome( char str[] ); int is_mirrored( char str[] );
Time of Update: 2018-12-05
歐拉路徑的問題。有向圖判定是否存在歐拉道路的步驟:判定連通,判定點的入度和出度的關係!首先,因為單詞的擺放是有方向的,所以要建一個有向圖。其中,要注意的是,很可能會有重邊出現,所以一定要做的一件事是記錄重邊的個數,因為在滿足圖去掉方向之後是連通的,那麼就看每個點入度和出度的關係就好;然後,判斷這個圖是否連通,如果不連通,可以肯定是沒有方案存在的;接下來是判斷一共有幾個點是入度和出度不等的,如果超過兩個點,就一定沒有歐拉道路存在;如果是2個點,要判定這個兩個點是不是一個是起點,一個是匯點,起點是出
Time of Update: 2018-12-05
#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 =