锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
瑙f硶濡備笅錛?br />
{
int best = 0;
int sum = 0;
for(int i = 0; i < a.length; i++)
{
sum = sum + a[i];
if(sum < 0 )
sum = 0;
else if(sum > best)
best = sum;
}
return best;
}
2.
Ugly Number: 鎵懼嚭絎琻涓兘琚?錛?錛?鏁撮櫎鐨勬暟
渚嬪錛?, 3, 4, 5, 6, 9,10, 12, 15, 20, 25 ... 絎?涓槸4錛?絎?涓槸5錛岀5涓槸6 ... 絎?00鏄紵
鎯蟲硶錛氶鍏堟槸浠?1寮濮嬶紝2錛?錛?鍒嗗埆涔?錛屾渶灝忕殑鏄?錛屾帴涓嬫潵灝辨槸2錛?鐨勪綅緗繘1錛?鍜?鐨勪綅緗笉鍙?
鍐嶆潵涓嬈★紝鏈灝忕殑鏄?錛?鐨勪綅緗繘1錛?鍜?浣嶇疆榪?錛屽啀鏉ヤ竴嬈★紝鏈灝忕殑鏄?錛?鍜?鐨勪綅緗笉鍙樸傘傘?br />
{
int a = new int[n+1]
a[0] = 1;
int i2 = 0, i3 = 0, i5 = 0;
int n2 = 0; n3 = 0; n5 = 0;
int m = 0;
for(int i = 0; i <= n; i++)
{
n2 = a[i2] * 2;
n3 = a[i3] * 3;
n5 = a[i5] * 5;
m = min(n2, n3, n5);
if(m == n2)
{
a[i] = m;
i2++;
}
//similar for i3 and i5
}
return a[n];
}
3. 鏈鍚庝竴涓棶棰橈細緇?i, j 涓や釜鏁幫紝鐒跺悗鎵撳嵃鍑?2^i 錛?^j 鐨勫簭鍒?br />
渚嬪錛?i = 3 j =4 灝辨墦鍗板嚭錛?br />
2^0 * 5 ^0 = 1
2^1 * 5^0 = 2
2^2 * 5 ^0 = 4
2^0 * 5^1 = 5
2^3 * 5^0 = 8
2^1 * 5^1 = 10
...
瑙f硶錛氬拰涓婇潰涓涓В娉曞緢鐩鎬技錛屼笉榪囨敞鎰忚澶勭悊鐩哥瓑鐨勬儏鍐碉紝姣斿2 * 2^1 * 5 ^1 = 20 2^2 * 5^0 ^5 = 20,
浠g爜灝變笉鍐欎簡銆?img src ="http://m.shnenglu.com/willcao/aggbug/176124.html" width = "1" height = "1" />
if ( n == 0 )
return 1;
if ( n == 1 )
return 1;
return fib ( n - 1 ) + fib ( n - 2 );
}
濂? 鎴戜滑灝辨崲涓狣P鐨勬柟寮忥細
if ( n == 0 || n == 1 )
return 1;
int [] f = new int[ n ];
f[ 0 ] = 1;
f[ 1 ] = 1;
for( int i = 2; i < n; i++)
{
f[ i ] = f[ i-1 ] + f[ i-2 ];
}
return f[ n-1 ];
}
00011
01111
11110
01110
榪欎釜鏈澶х殑閭d釜鍏ㄦ槸1鐨剆ubmatrix鐨勫ぇ灝忓氨鏄?.鐪嬭搗鏉ユ尯闅撅紝鍏跺疄铔鏄撶殑銆?br />鎴戜滑鍏堢敤鏈騫沖父鐨勬濊礬鏉ヨВ涓涓嬪惂銆?br />鍏堝垵濮嬪寲鍙﹀涓涓悓鏍峰ぇ灝忕殑n*n鐨刴atrix
絎竴琛屽拰絎竴鍒楀緢瀹規槗錛屽拰鍘熷厛涓鏍風殑鍊?br />00011
0
0
1
0
鎺ヤ笅鏉ワ紝綆楃浜岃錛屽拰鍏朵粬鐨勮銆傝嚜宸卞姩鎵嬶紝浣犲氨鐭ラ亾鍏跺疄灝辨槸
s[i][j] = min(s[i][j-1],s[i-1][j],s[i-1][j-1]) + 1
鎴戜滑欏轟究榪樺彲浠ュ姞涓婁竴涓猰ax,璁板綍鏈澶х殑鍊箋?br />榪欐牱榪欎釜灝辨悶瀹氫簡銆侱P浠嬬粛瀹屾瘯銆傛帴涓嬫潵寮濮嬪叧浜嶴tring鐨凞P
1.鎵懼埌涓や釜瀛楃涓茬殑鏈澶х浉鍚屽瓧涓茬殑闀垮害
渚嬪錛歛baabb aabbaa 鏈澶х殑鐩稿悓瀛椾覆aabb闀垮害灝辨槸4.
瑙f硶錛氱粰涓や釜涓?p,q 鎴戜滑鏈?br />c(i,j) = 0 if p[i] != q[j]
c(i,j) = c(i-1,j-1) + 1 if p[i] = q[j].
浠g爜鍜屼笂闈ubmatrix寰堢浉浼箋傚厛鍒濆鍖栬竟緙橈紝鐒跺悗綆楀嚭鍏朵粬鐨勫?br />2.鎵懼埌涓や釜瀛楃涓茬殑鏈澶ubsequence鐨勯暱搴?br />渚嬪錛歛cbbab abbca 鏈澶х殑subsequence is abba 闀垮害鏄?.
瑙f硶錛氱粰涓や釜涓?p,q 鎴戜滑鏈?br />c(i,j) = max(c(i-1,j),c(i,j-1)) if p[i] != q[j]
c(i,j) = c(i-1,j-1) + 1 if p[i] = q[j]
3.鎵懼埌涓涓瓧絎︿覆鏈澶х殑Palindrom
渚嬪: abcdedcbdsa 鏈澶х殑Palindrom灝辨槸bcdedcb 闀垮害鏄?
瑙f硶錛氱粰涓涓覆p
c(i,j) = max(c(i+1,j),c(i,j-1)) if p[i] != q[j]
c(i,j) = c(i+1,j-1) + 2 if p[i] = q[j]
rsync --progress --avze ssh --delete srcDir/ remoteName@remoteMachine:remoteDir/
-a quick way to specify the recursion and preserve everything.
-v verbose
-z compress
And then change ssh with no password:
Create the private keys for local machine:
Copy the local keys to remote machine:ssh-keygen -t dsa
Do not set the password. ssh-copy-id -i ~/.ssh/id_dsa.pub remoteuser@remotebox
After that, add an alias into your .bashrc
alias bp='. ~/backup.sh'
So you can run bp directly to backup all things.
Over ~~~
寰堝ソ鐨勪竴綃囨枃绔狅紝灝ゅ叾鏄噷闈㈢殑紱佺敤ipv6
2.鍦ㄤ嬌鐢ㄤ竴涓柊鐗堟湰浠ュ悗錛屽彲鑳戒細鍑虹幇mapreduce鑳藉惎鍔紝浣嗘槸dfs鏃犳硶鍚姩鐨勬儏鍐點傚嵆浣夸綘format namenode榪樻槸涓嶈銆傝繖涓鎴戦儊闂蜂簡濂戒箙銆俶apreduce 閮藉彲浠ュ惎鍔紝浣嗗氨鏄痙fs鏃犳硶鍚姩銆俤atanode灝辨槸鍚姩涓嶄簡銆傛兂浜嗗ソ涔咃紝鎬葷畻鎯蟲槑鐧戒簡銆傚洜涓篸atanode閲岄潰鏈夋暟鎹紝鍙槸namenode閲岄潰鍗存牸寮忓寲浜嗐傚姙娉曪細鍒犻櫎鎵鏈塪atanode涓殑鏁版嵁銆?br>
浣跨敤ssh 榪滅▼鎵ц鍛戒護
ssh gp09@***.comp.nus.edu.sg 'mkdir hadoop'
涓嶈繃ssh鏈変竴涓瘮杈冪儲鐨勫湴鏂癸紝灝辨槸涓嶈兘鐢╟d鍛戒護銆傛墍浠ュ湪浣跨敤鐨勬椂鍊欒灝忓績銆?br>
鍦╨inux鎴栬卽nix涓畨瑁卆nt
緙栬緫.bashrc 鏂囦歡
娣誨姞錛?br>export ANT_HOME=~/files/....
export JAVA_HOME=/usr/lib/jvm/java-6-sun/jre/bin/java
export PATH=$(PATH):$(ANT_HOME)/bin
鏈熶腑$琛ㄧず鎻愬彇鍙橀噺錛?琛ㄧず鍦ㄥ悗闈㈡坊鍔犮?br>
#include<iostream>
2using namespace std ;
3
4typedef void (*pfn) (void);
5union msg
6{
7 pfn first ;
8 int (* ifn)(int a ,int b );
9 void(*vfn)(int ,int );
10};
11int OnInt(int a ,int b )
12{
13 cout<<a<<" "<<b<<endl;
14 return a ;
15}
16void OnVoid(int a ,int b )
17{
18 cout<<a <<" "<<b<<endl;
19}
20int main()
21{
22 pfn p=(pfn)(int (*)(int ,int ))OnInt;
23 msg m;
24 m.first=p;
25 cout<<(m.ifn)(5,6)<<endl;
26
27 p=(pfn)(void (*)(int, int ))OnVoid;
28 m.first=p;
29 m.vfn(10,15);
30 return 0;
31}
鐪嬩簡榪欐浠g爜浼氳浜烘兂鍒頒粈涔堝憿?鎯沖埌鐨勫簲璇ユ槸MFC涓偅浜涙秷鎭嚱鏁板惂.涓嶅悓鐨勬秷鎭?鍙傛暟涓嶄竴鏍?榪斿洖鍊間篃涓嶄竴鏍?鑰屽湪瀹氫箟鐨勬椂鍊欏彧鏄竴涓寚閽?鍙槸鍦ㄨ皟鐢ㄧ殑鏃跺欏嵈鏈夊悇縐嶅悇鏍風殑鏂瑰紡.鍙﹀榪欐浠g爜鏈鏈夋剰鎬濈殑灝辨槸鎵撶牬甯歌,灝辯敤浜唘nion鍚屾椂鍙湁涓涓彉閲忓湪璧蜂綔鐢?騫蟲椂涔︿笂鎬繪槸璇村叾浠栧彉閲忛兘涓嶈兘鐢?浠婂ぉ灝辯敤緇欎綘鐪嬬湅,鐢ㄧ殑榪樺緢鐗?..
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
int main(void)
{
pid_t pid=fork();
if(pid==0)
{
int j ;
for(j=0;j<10;j++)
{
printf("child: %d\n",j);
sleep(1);
}
}
else if (pid>0)
{
int i;
for(i=0;i<10;i++)
{
printf("parent: %d\n",i);
sleep(1);
}
}
else
{
fprintf(stderr,"can't fork ,error %d\n",errno);
exit(1);
}
printf("This is the end !");
}
鍏堣創淇″彿閲忕殑浠g爜.
#include<stdio.h>
#include<sys/time.h>
#define MAX 10
pthread_t thread[2];
pthread_mutex_t mut;
int number=0,i;
void * thread1()
{
printf("thread1: I'm thread 1 \n");
for(i =0;i<MAX ;i++)
{
printf("thread 1: number=%d \n",number);
pthread_mutex_lock(&mut);
number++;
pthread_mutex_unlock(&mut);
sleep(2);
}
printf("thread1: 涓誨嚱鏁板湪絳夋垜瀹屾垚浠誨姟鍚楋紵\n");
pthread_exit(NULL);
}
void * thread2()
{
printf("thread2: I'm thread 2 \n");
for(i =0; i<MAX;i++)
{
printf("thread2 : number=%d\n",number);
pthread_mutex_lock(&mut);
number++;
pthread_mutex_unlock(&mut);
sleep(3);
}
printf("thread2 : 涓誨嚱鏁板湪絳夋垜瀹屾垚浠誨姟涔堬紵\n");
pthread_exit(NULL);
}
void thread_create(void)
{
/*鍒涘緩綰跨▼*/
pthread_create(&thread[0],NULL,thread1,NULL);
printf("綰跨▼1琚垱寤猴紒\n");
pthread_create(&thread[1],NULL,thread2,NULL);
printf("綰跨▼2琚垱寤猴紒\n");
}
void thread_wait(void)
{
/*絳夊緟綰跨▼緇撴潫*/
pthread_join(thread[0],NULL);
printf("綰跨▼1宸茬粡緇撴潫錛乗n");
pthread_join(thread[1],NULL);
printf("綰跨▼2宸茬粡緇撴潫!\n");
}
int main()
{
/*鐢ㄩ粯璁ゅ睘鎬у垵濮嬪寲浜掓枼閿?/
pthread_mutex_init(&mut,NULL);
printf("鎴戞槸涓誨嚱鏁幫紝鎴戞鍦ㄥ垱寤虹嚎紼嬶紒\n");
thread_create();
printf("鎴戞槸涓誨嚱鏁幫紝鎴戞鍦ㄧ瓑寰呯嚎紼嬪畬鎴愪換鍔★紒\n");
thread_wait();
}
鎵ц鐨勭粨鏋滄槸:
thread1: I'm thread 1
thread 1: number=0
綰跨▼1琚垱寤猴紒
thread2: I'm thread 2
thread2 : number=1
綰跨▼2琚垱寤猴紒
鎴戞槸涓誨嚱鏁幫紝鎴戞鍦ㄧ瓑寰呯嚎紼嬪畬鎴愪換鍔★紒
thread 1: number=2
thread2 : number=3
thread 1: number=4
thread 1: number=5
thread2 : number=6
thread 1: number=7
thread2 : number=8
thread 1: number=9
thread2 : number=10
thread1: 涓誨嚱鏁板湪絳夋垜瀹屾垚浠誨姟鍚楋紵
綰跨▼1宸茬粡緇撴潫錛?br>thread2 : 涓誨嚱鏁板湪絳夋垜瀹屾垚浠誨姟涔堬紵
綰跨▼2宸茬粡緇撴潫!
鑰屾垜浠敤鑷棆閿?浠g爜:
* time :2008.4.30
* author:will cao
* Email:sei_michael@126.com
* 鎺㈢儲鑷棆閿佷笌淇″彿閲忕殑鍖哄埆
*/
#include<pthread.h>
#include<stdio.h>
pthread_t thread[2];
pthread_spinlock_t lock ;
#define MAX 10
int number=0,i;
void * thread1()
{
printf ("thread 1 :I began to run !");
for(i=0;i<MAX;i++)
{
printf("thread 1 :number=%d \n",number);
pthread_spin_lock(&lock);
number++;
pthread_spin_unlock(&lock);
}
printf("ok ,I am over !\n");
pthread_exit(NULL);
}
void * thread2 ()
{
printf("thread2 : I start !!!\n");
for(i=0;i<MAX;i++)
{
printf("thread2 : number = %d \n",number);
pthread_spin_lock(&lock);
number++;
pthread_spin_unlock(&lock);
}
printf("thread 2: I am over!!!");
pthread_exit(NULL);
}
void thread_create(void)
{
/*create the threads */
pthread_create(&thread[0],NULL,thread1,NULL);
printf("create the thread 1\n ");
pthread_create(&thread[1],NULL,thread2,NULL);
printf("create the thread 2 \n");
}
void thread_wait(void )
{
/*wait for the thread to be over */
pthread_join(thread[0],NULL);
printf("the thread 1 is over !\n");
pthread_join(thread[1],NULL);
printf("the thread 2 is over ! \n");
}
int main()
{
/* init the spin lock */
pthread_spin_init(&lock,0);
printf("i am the main,and I am creating the threads ");
thread_create();
printf("i am the main,and I am wait for the thread to be over!");
thread_wait();
}
thread 1 :number=1
thread 1 :number=2
thread 1 :number=3
thread 1 :number=4
thread 1 :number=5
thread 1 :number=6
thread 1 :number=7
thread 1 :number=8
thread 1 :number=9
ok ,I am over !
create the thread 1
thread2 : I start !!!
create the thread 2
i am the main,and I am wait for the thread to be over!thread2 : number = 10
thread2 : number = 11
thread2 : number = 12
thread2 : number = 13
thread2 : number = 14
thread2 : number = 15
thread2 : number = 16
thread2 : number = 17
thread2 : number = 18
thread2 : number = 19
thread 2: I am over!!!the thread 1 is over !
the thread 2 is over !
鎬葷粨:浠庤〃闈笂鏉ョ湅,寰堟槑鏄劇殑鍖哄埆鏄綋鎴戜滑鐢ㄧ殑鏄俊鍙烽噺鐨勬椂鍊?榪欎釜鏃跺欐槸鏈夎皟搴︾殑.鍥犱負浠庤繍琛岀粨鏋滀笂鏉ョ湅,涓葷嚎紼嬪湪鍒涘緩鍏朵粬涓や釜綰跨▼鍚?鍏朵粬綰跨▼寮濮嬭繍琛?騫朵笖涓葷嚎紼嬩篃鍦ㄨ繍琛?浣嗘庝箞榪愯榪欎釜鏄棤娉曠‘瀹氱殑,榪欐槸涓涓茍鍙戠殑榪囩▼.
褰撲嬌鐢ㄨ嚜鏃嬮攣鍚?榪欎釜灝變笉涓鏍蜂簡.褰撹繍琛屽埌涓寸晫鍖虹殑鏃跺?瀹冩槸鐩存帴鐨勮繃鍘?涓嶆槸浼氫駭鐢熶竴涓瓑寰?鎴栬呬竴涓皟搴?
涓嶇煡閬撶紪璇戝櫒鏄庝箞緙栬瘧鐨?寰堟兂鐭ラ亾緙栬瘧鍚庝簩榪涘埗浠g爜鏈変粈涔堝尯鍒?浣嗚繖涓ソ鍍忔湁鐐瑰お闅?...涓嶈繃鎴戣寰椾粠榪愯緇撴灉涓婃潵鐪嬭繖涔堝,搴旇宸笉澶氫簡.
鍐嶆潵鐪嬬湅淇″彿閲?淇″彿閲忕殑瀹炵幇灝變笉榪欒埇綺懼噯浜?濡傛灉浣跨敤涓涓俊鍙烽噺鏉ユ帶鍒朵竴涓復鐣屽尯鐨勮瘽.灝變細鏈夊緢澶氭儏鍐?棣栧厛鏈鏄庢樉鐨勬槸璇昏?鍐欒呴棶棰?鍙互鏈夊涓鑰?鍐欒呭彧鍙互鏈変竴涓?騫朵笖淇″彿閲忕殑瀹炵幇涔熷拰鑷棆閿佹湁鑰呬竴瀹氱殑鍖哄埆.褰撲竴涓俊鍙烽噺涓嶈兘璁塊棶鍚?榪涚▼涓嶄細鍦ㄩ偅閲屽驚鐜?浼氳鐫$湢鎺?褰撲俊鍙烽噺鍙互浣跨敤鐨勬椂鍊?璋冨害鍣ㄤ細浠庡彲浠ヨ皟搴︾殑榪涚▼閫夋嫨涓涓?
鍩烘湰涓婂氨榪欎釜鏍峰瓙.
鏈涘鎬?澶氭兂,澶氳.鐝嶆儨闈掓槬.