锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久美女人爽女人爽,色偷偷88欧美精品久久久,久久综合视频网http://www.shnenglu.com/luyulaile/archive/2013/03/31/198974.htmlluisluisSat, 30 Mar 2013 21:26:00 GMThttp://www.shnenglu.com/luyulaile/archive/2013/03/31/198974.htmlhttp://www.shnenglu.com/luyulaile/comments/198974.htmlhttp://www.shnenglu.com/luyulaile/archive/2013/03/31/198974.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/198974.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/198974.html鍘熸枃鍦板潃: http://blog.csdn.net/gfaiswl/article/details/4749713

1.闂瀹氫箟

      TSP闂錛堟梾琛屽晢闂錛夋槸鎸囨梾琛屽瑕佹梾琛宯涓煄甯傦紝瑕佹眰鍚勪釜鍩庡競緇忓巻涓斾粎緇忓巻涓嬈$劧鍚庡洖鍒板嚭鍙戝煄甯傦紝騫惰姹傛墍璧扮殑璺▼鏈鐭?/p>

      鍋囪鐜板湪鏈夊洓涓煄甯傦紝0,1,2,3錛屼粬浠箣闂寸殑浠d環濡傚浘涓錛屽彲浠ュ瓨鎴愪簩緇磋〃鐨勫艦寮?br />

              image        image

                      鍥句竴                                                                                               

        鐜板湪瑕佷粠鍩庡競0鍑哄彂錛屾渶鍚庡張鍥炲埌0錛屾湡闂?錛?錛?閮藉繀欏誨茍涓斿彧鑳界粡榪囦竴嬈★紝浣夸唬浠鋒渶灝忋?/p>

2.鍔ㄦ佽鍒掑彲琛屾?/h1>

        璁緎, s1, s2, …, sp, s鏄粠s鍑哄彂鐨勪竴鏉¤礬寰勯暱搴︽渶鐭殑綆鍗曞洖璺紝鍋囪浠巗鍒頒笅涓涓煄甯俿1宸茬粡姹傚嚭錛屽垯闂杞寲涓烘眰浠巗1鍒皊鐨勬渶鐭礬寰勶紝鏄劇劧s1, s2, …, sp, s涓瀹氭瀯鎴愪竴鏉′粠s1鍒皊鐨勬渶鐭礬寰勶紝鎵浠SP闂鏄瀯鎴愭渶浼樺瓙緇撴瀯鎬ц川鐨勶紝鐢ㄥ姩鎬佽鍒掓潵姹傝В涔熸槸鍚堢悊鐨勩?/p>

3.鎺ㄥ鍔ㄦ佽鍒掓柟紼?/h1>

        鍋囪浠庨《鐐箂鍑哄彂錛屼護d(i, V’)琛ㄧず浠庨《鐐筰鍑哄彂緇忚繃V’(鏄竴涓偣鐨勯泦鍚?涓悇涓《鐐逛竴嬈′笖浠呬竴嬈★紝鏈鍚庡洖鍒板嚭鍙戠偣s鐨勬渶鐭礬寰勯暱搴︺?/p>

        鎺ㄥ錛?鍒嗘儏鍐墊潵璁ㄨ)

        ①褰揤’涓虹┖闆嗭紝閭d箞d(i, V’)錛岃〃紺轟粠i涓嶇粡榪囦換浣曠偣灝卞洖鍒皊浜嗭紝濡備笂鍥劇殑 鍩庡競3->鍩庡競0(0涓鴻搗鐐瑰煄甯?銆傛鏃禿(i, V’)=Cis(灝辨槸 鍩庡競i 鍒?鍩庡競s 鐨勮窛紱?銆?/p>

        ②濡傛灉V’涓嶄負絀猴紝閭d箞灝辨槸瀵瑰瓙闂鐨勬渶浼樻眰瑙c備綘蹇呴』鍦╒’榪欎釜鍩庡競闆嗗悎涓紝灝濊瘯姣忎竴涓紝騫舵眰鍑烘渶浼樿В銆?/p>

           d(i, V’)=min{Cik +  d(k, V’-{k})}

           娉細Cik琛ㄧず浣犻夋嫨鐨勫煄甯傚拰鍩庡競i鐨勮窛紱伙紝d(k, V’-{k})鏄竴涓瓙闂銆?/p>

        緇間笂鎵榪幫紝TSP闂鐨勫姩鎬佽鍒掓柟紼嬪氨鍑烘潵浜嗭細

         image

4.瀹炰緥鍒嗘瀽

     鐜板湪瀵歸棶棰樺畾涔変腑鐨勪緥瀛愭潵璇存槑TSP鐨勬眰瑙h繃紼嬨?鍋囪鍑哄彂鍩庡競鏄?0鍩庡競)

     image

    ①鎴戜滑瑕佹眰鐨勬渶緇堢粨鏋滄槸d(0,{1,2,3}),瀹冭〃紺猴紝浠庡煄甯?寮濮嬶紝緇忚繃{1,2,3}涔嬩腑鐨勫煄甯傚茍涓斿彧鏈変竴嬈★紝姹傚嚭鏈鐭礬寰?

    ②d(0,{1,2,3})鏄笉鑳戒竴涓嬪瓙姹傚嚭鏉ョ殑錛岄偅涔堜粬鐨勫兼槸鎬庝箞寰楀嚭鐨勫憿錛熺湅涓婂浘鐨勭浜屽眰錛岀浜屽眰琛ㄦ槑浜哾(0,{1,2,3})鎵闇渚濊禆鐨勫箋傞偅涔堝緱鍑猴細

       d(0,{1,2,3})=min  {

                                    C01+d(1,{2,3})

                                    C02+d{2,{1,3}}

                                    C03+d{3,{1,2}}

                                  }

     ③d(1,{2,3})錛宒(2,{1,3})錛宒(3,{1,2})鍚屾牱涔熶笉鏄竴姝ュ氨鑳芥眰鍑烘潵鐨勶紝瀹冧滑鐨勮В涓鏍烽渶瑕佹湁渚濊禆錛屽氨姣斿璇磀(1,{2,3})

       d(1,{2,3})=min{

                              C12+d(2,{3})                             

                              C13+d(3,{2})

                              }

       d(2,{1,3})錛宒(3,{1,2})鍚屾牱闇瑕佽繖涔堟眰銆?/p>

    ④鎸夌収涓婇潰鐨勬濊礬錛屽彧鏈夋渶鍚庝竴灞傜殑錛屽綋褰揤’涓虹┖闆嗘椂錛孋is鐨勫兼墠鍙互姹傦紝瀹冪殑鍊兼槸鐩存帴浠?/p>

image

榪欏紶琛ㄩ噷姹傚緱鐨勩?/p>

     5.緙栫▼鎬濊礬

        灝哾(i, V’)杞崲鎴愪簩緇磋〃錛宒[i][j]

image

        鍦ㄧ▼搴忎腑妯℃嫙濉〃鐨勮繃紼嬶紝涓昏瑕佽冭檻鍒癹榪欎釜鍙傛暟鐨勮〃紺猴紝瀹冭浠h〃涓涓泦鍚堬紝鍙互鐢ㄤ簩緇存暟緇勬潵琛ㄧず銆?/p>

   6.婧愪唬鐮?/h1>

娉細鐢變簬鏈漢姘村鉤鏈夐檺錛屽茍涓斾富瑕佸湪榪欓噷鏄綋鐜版濊礬錛屾墍浠ョ▼搴忓茍涓嶆槸寰堝畬鍠勶紝浠g爜璐ㄩ噺涔熶笉楂橈紝寰堝湴鏂瑰彲浠ュ啓寰楅氱敤涓浜涳紝鎵浠ヨ繖閲屽彧鏄彁渚涗竴涓弬鑰冿紝紼嬪簭鐨勮繘涓姝ュ畬鍠勶紝鐢辮鑰呰嚜鐢卞彂鎸ャ?/p>

#include 
#include

int IsIncluded(int x,int array[3])//x鏄惁鍖呭惈鍦ㄦ暟緇勪腑 

    if((array[0] != x) && (array[1] != x) && (array[2] != x)) 
        return 0; 
    return 1; 

int Left(int k,int array[3],int V[8][3])//瀹炵幇V'-{k} 鐨勪笅鏍囨绱?nbsp;

    int i = 0,index = 0,array_0_count = 0,array_1_count = 0,array_2_count = 0,array_3_count = 0; 
    int V_0_count = 0,V_1_count = 0,V_2_count = 0,V_3_count = 0; 
    int temp[3]; 
    for(i = 0; i < 3; i++) 
        temp[i] = array[i]; 
    for(i = 0; i < 3; i++) 
        if(temp[i] == k) 
            temp[i] = 0;  //鐩稿綋浜庡幓鎺塳榪欎釜鍩庡競 
    for(i = 0; i < 3; i++) 
    { 
        if(temp[i] == 0) 
            array_0_count++; 
        else if(temp[i] == 1) 
            array_1_count++; 
        else if(temp[i] == 2) 
            array_2_count++; 
        else 
            array_3_count++; 
    } 
    for(index = 0; index < 8; index++) 
    { 
        for(i=0; i < 3; i++) 
        { 
            if(V[index][i] == 0) 
                V_0_count++; 
            else if(V[index][i] == 1) 
                V_1_count++; 
            else if(V[index][i] == 2) 
                V_2_count++; 
            else 
                V_3_count++; 
        } 
        if((array_0_count == V_0_count) && (array_1_count == V_1_count) 
            && (array_2_count == V_2_count) && (array_3_count == V_3_count)) 
            return index; 
        V_0_count = 0; 
        V_1_count = 0; 
        V_2_count = 0; 
        V_3_count = 0; 
    } 
    return 0; 
}

void TSP(int d[4][8],int c[4][4],int V[8][3],int n) 

    int i = 0,j = 0,k = 0;

    for(i = 1; i < n; i++)//V'涓虹┖鏃訛紝緇欒祴鍊鹼紝 
        d[i][0] = c[i][0];

    for(j = 1; j < 7; j++)//鎸夊垪閬嶅巻涓嶅悓闆嗗悎錛寋1},{2},{3},{1,2},{1,3}..... 
    { 
        for(i = 1; i < n; i++)//閬嶅巻鍩庡競1錛?錛? 
        { 
            if( !IsIncluded(i,V[j]) )//i蹇呴』涓嶅湪闆嗗悎涓紝鍚﹀垯灝卞睘浜庣粡榪囦袱嬈★紝涓嶇鍚堥鎰?nbsp;
            { 
                for(k = 0; k < 3; k++)//鍒嗗埆璇曟帰闆嗗悎涓殑姣忎竴鐐癸紝鍙栨渶灝忓?nbsp;
                { 
                    if((V[j][k] != 0) && ((c[i][V[j][k]] + d[V[j][k]][Left(V[j][k],V[j],V)]) < d[i][j])) 
                        d[i][j] = c[i][V[j][k]] + d[V[j][k]][Left(V[j][k],V[j],V)]; 
                } 
            } 
        }//end of     for(i = 1; i < n; i++)//閬嶅巻鍩庡競1錛?錛? 
    }//end of for(j = 1; j < ((int)pow(2,n)-1); j++) 
    for(k = 0; k < 3; k++)//鍒嗗埆璇曟帰涓嬩竴姝ヤ負闆嗗悎涓殑浠諱綍涓鐐癸紝鍙栨渶灝忓?nbsp;
    { 
        if((V[7][k] != 0) && (c[0][V[7][k]] + d[V[7][k]][Left(V[7][k],V[7],V)]) < d[0][7]) 
            d[0][7] = c[0][V[7][k]] + d[V[7][k]][Left(V[7][k],V[7],V)]; 
    } 

void main() 

    int V[8][3]= 
    { 
        0,0,0, 
        0,0,1, 
        0,0,2, 
        0,0,3, 
        0,1,2, 
        0,1,3, 
        0,2,3, 
        1,2,3 
    }; 
    int c[4][4]= 
    { 
        0,3,6,7, 
        5,0,2,3, 
        6,4,0,2, 
        3,7,5,0 
    }; 
    int d[4][8]={0},i=0,j=0;

    for(i=0; i<4; i++) 
        for(j=0; j<8; j++) 
            d[i][j]=1000;   //鍋囪1000涓烘棤絀峰ぇ 
    TSP(d,c,V,4); 
    printf("The least road is:%d/n",d[0][7]); 
}



luis 2013-03-31 05:26 鍙戣〃璇勮
]]>joj 1815 The Smart Bunny 鍔ㄦ佽鍒?璇﹁Вhttp://www.shnenglu.com/luyulaile/archive/2009/07/20/90642.htmlluisluisMon, 20 Jul 2009 09:19:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/20/90642.htmlhttp://www.shnenglu.com/luyulaile/comments/90642.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/20/90642.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/90642.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/90642.html

2nd JOJ Cup Online VContest Problem

We all know that bunny is fond of carrots. One cloudy day, he was told that there would be a violenting flood coming soon to destroy the forests. He was scared and after not thinking too much he told himself that he had to escape. He suddenly recalled that there was a temple on the top of the hill and he might shelter there until the flood's past. But unfortunately there was no food for him on the top of the hill, so he had to take his carrots away along with himself. Then he moved to the foot of the hill and stopped. There was only one way for him to get the top of the hill, that is, a long staircase. Given the number of the steps of the staircase, he asked himself:"how many different ways of strides are there for him to get the top of the hill?". Of course, because of his height, he could only stride a limited range of steps. He was smart so much so that he got the answer quickly. Do you know how he did it?

Input Specification

The input consists of several test cases, each of which occupies a line containing M(1<=M<=40) and N(1<=N<=10), where M indicates the number of the steps of the staircase and N indicates the maximal number of steps the bunny can stride once.

Output Specification

Each test case should correspond to a line in the output. Your program should print an integer which is the answer.

Sample Input

4 2
5 4

Sample Output

5
15


棰樻剰鏄竴鍙厰瀛愯鍒拌窛紱諱負M錛堝崟浣嶄負1錛夌殑鍦版柟錛屽畠姣忔鏈澶氳蛋N錛岄棶鏈夊灝戠鏂規硶銆傝緭鍏  N 杈撳嚭r[m][n];


瑙f瀽錛氳涓簉[i][j]錛岃〃紺鴻窛紱繪誨叡i涓旀瘡嬈℃渶澶氳蛋j鐨勬柟娉曟暟(鍙互娌℃湁璧板嚭閭eぇ灝忎負j鐨勯偅姝ワ紝鍙槸鍏佽璧伴偅姝ヨ屽凡)銆?br>
鏍規嵁鏈鍚庨偅涓姝ュ彲鑳借蛋鐨勯暱搴︼紝r[i-2][j]琛ㄧず鏈鍚庨偅姝ヨ窛紱諱負2.r[i-j][j]琛ㄧず鏈鍚庨偅姝ヨ窛紱諱負j.
寤虹珛閫掓帹鍏崇郴r[i][j]=r[i-1][j]+r[i-2][j]+r[i-3][j]+r[i-j][j];
//鏈漢瑙夊緱榪欓噷鐗瑰埆闅炬兂錛屾兂鍒頒簡涔熻寰楁棤娉曞緩绔嬮掓帹鍏崇郴鍛錛宩涓嶆槸涓鐩翠笉鍙樺悧錛?br>紲炲鐨勫湴鏂瑰湪浜庡彲浠ヤ護r[0][j]=r[1][j]=1;褰撶劧榪樻湁r[i][1]=1
-----------棰勫鐞?---
for(j=0;j<n;j++)

       {

              r[0][j]=1;

              r[1][j]=1;

       }

       for(i=0;i<n;i++)

              r[i][1]=1;


---dp----------
 for(i=2;i<m;i++)
    for(j=2;j<n;j++)
    {
     if(i<j)
        r[i][j]=r[i][i]; //榪欑偣闈炲父閲嶈
     else 
       for(k=1;k<=j;k++)
        {
   r[i][j]+=r[i-k][j];
        }
    }
------------
r[1][1]=1
r[2][1]=1
r[2][2]=r[2][1]+r[2][2]=2;
r[3][1]=1;
r[3][2]=r[2][2]+r[1][2]=3;
r[3][3]=r[0][3]+r[1][3]+r[2][3]=4;



luis 2009-07-20 17:19 鍙戣〃璇勮
]]>
joj 1762 Dollars 鍔ㄦ佽鍒?璇﹁Вhttp://www.shnenglu.com/luyulaile/archive/2009/07/19/90547.htmlluisluisSun, 19 Jul 2009 13:45:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/19/90547.htmlhttp://www.shnenglu.com/luyulaile/comments/90547.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/19/90547.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/90547.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/90547.htmlNew Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up in 4 ways: 1 20c, 2 10c, 10c+2 5c, and 4 5c.

Input

Input will consist of a series of real numbers no greater than $50.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).

Output

Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 5), followed by the number of ways in which that amount may be made up, right justified in a field of width 12.

Sample input

 

0.20
2.00
0.00

Sample output

 

0.20           4
2.00         293
鍏稿瀷鐨勫姩鎬佽鍒掗棶棰橈細
鍙互鍏堣冭檻鍙湁n-1縐嶇‖甯侊紝V1,V2,V3,---Vn-1.璁懼噾鎴愭誨間負M鐨勬柟娉曟暟涓簉esult[M];
鐜板湪鍙堟坊鍔犱竴縐嶉潰鍊間負Vn鐨勭‖甯併?/pre>
鍒欏挶浠渶瑕佷慨鏀逛竴浜涘鹼紝淇敼閭d簺澶т簬絳変簬Vn鐨剅esult[],涓嶅Θ璁綧澶т簬vn銆?/pre>
鏂皉esult[M]=鍘焤esult[M]+result[M-Vn]+result[M-2*Vn]+----鐩村埌M-p*Vn<=0;錛?錛?/pre>
瀹為檯涓婂鏋滃(2)閭f牱澶勭悊 浠庡ぇ浜庣瓑浜嶸n鐨剅esult[]寮濮嬪鐞嗙殑璇濓紝浠庡皬鍒板ぇ錛岃Vn=M-p*Vn;
鍒檙esult[M-p*Vn]絎竴涓渶鍏堟洿鏂幫紝result[M-p*Vn]+=result[M-p*Vn -Vn]   瑙?span style="COLOR: red">(2)
闅忓悗鏇存柊result[M-(p-1)*vn]錛屽垯鍙渶鐩存帴鍔犱笂result[M-p*Vn]鐨勫鹼紝鏃犻渶濡傦紙1錛夊紡閭f牱 绱姞銆?/pre>
鐢ㄧ▼搴忚〃杈懼氨鏄?/pre>
int coin[10]={5,10,20,50,100,200,500,1000,2000,5000};
for(i=1;i<10;i++)
 for(j=coin[i];j<=50000;j+=5)
     result[j]+=result[j-Coin[i]];   (2) //
-------------
榪樻湁涓涓敞鎰忕偣錛岃鐗涗漢鍗氬錛?a >http://hi.baidu.com/piaoshi111/blog/item/9a6de84a00a6e5f882025c89.html
灝辨槸嫻偣鏁扮殑鍥涜垗浜斿叆錛?/pre>
1.5錛屾誕鐐規暟鍙兘琛ㄤ負1.4999999錛屾墍浠ヤ箻浠?00鏃惰漿鍖栦負鏁村瀷鏄?49錛屽簲褰撴敞鎰忋?/pre>


luis 2009-07-19 21:45 鍙戣〃璇勮
]]>joj 1832 Little Shop of Flowershttp://www.shnenglu.com/luyulaile/archive/2009/07/14/89995.htmlluisluisTue, 14 Jul 2009 02:05:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/14/89995.htmlhttp://www.shnenglu.com/luyulaile/comments/89995.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/14/89995.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/89995.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/89995.html

You want to arrange the window of your flower shop in a most pleasant way. You have F bunches of flowers, each being of a different kind, and at least as many vases ordered in a row. The vases are glued onto the shelf and are numbered consecutively 1 through V, where V is the number of vases, from left to right so that the vase 1 is the leftmost, and the vase V is the rightmost vase. The bunches are moveable and are uniquely identified by integers between 1 and F. These id-numbers have a significance: They determine the required order of appearance of the flower bunches in the row of vases so that the bunch i must be in a vase to the left of the vase containing bunch j whenever i < j. Suppose, for example, you have bunch of azaleas (id-number=1), a bunch of begonias (id-number=2) and a bunch of carnations (id-number=3). Now, all the bunches must be put into the vases keeping their id-numbers in order. The bunch of azaleas must be in a vase to the left of begonias, and the bunch of begonias must be in a vase to the left of carnations. If there are more vases than bunches of flowers then the excess will be left empty. A vase can hold only one bunch of flowers.

Each vase has a distinct characteristic (just like flowers do). Hence, putting a bunch of flowers in a vase results in a certain aesthetic value, expressed by an integer. The aesthetic values are presented in a table as shown below. Leaving a vase empty has an aesthetic value of 0.

 

 

V A S E S

 

 

1

2

3

4

5

Bunches

1 (azaleas)

7

23

-5

-24

16

2 (begonias)

5

21

-4

10

23

3 (carnations)

-21

5

-4

-20

20

 

According to the table, azaleas, for example, would look great in vase 2, but they would look awful in vase 4.

To achieve the most pleasant effect you have to maximize the sum of aesthetic values for the arrangement while keeping the required ordering of the flowers.

ASSUMPTIONS

1 ≤ F ≤ 100 where F is the number of the bunches of flowers. The bunches are numbered 1 through F. F ≤ V ≤ 100 where V is the number of vases. -50 ≤ Aij ≤ 50 where Aij is the aesthetic value obtained by putting the flower bunch i into the vase j.

Input

The first line contains two numbers: F and V.

The following F lines: Each of these lines contains V integers, so that Aij is given as the j’th number on the (i+1)’st line of the input file.

Notice: The input contains several test cases.

Output

The output line will contain the sum of aesthetic values for your arrangement.

Sample Input

3 5
7 23 -5 -24 16
5 21 -4 10 23
-21 5 -4 -20 20

Sample Output

53

榪欓鍙互鐢ㄦ悳绱㈣繃錛屼絾鏄繕鍙互鐢╠p
鐢╮esult[i][j]琛ㄧず鍓峣琛岋紝浠緇撳熬鐨勬帓娉曠殑鏈澶у鹼紝
rsult[1][j]鐩存帴鍒濆鍖栦負num[i][j];鍏朵綑鍒濆鍖栦負璐熸棤絀?br>dp鐨勮繃紼嬪氨鏄?br>    for(i=2;i<-r;i++)//琛岄愭笎澧炲姞
          for(j=i;j<=c;j++)//鍒楀繀欏誨ぇ浜庣瓑浜庤鍙鳳紝鍚﹀垯鏃犳硶淇濊瘉浠庡乏涓婃柟鍒板彸涓嬫柟
                    for(k=1;k<j;k++)
                               if(result[i][j]<result[i-1][k]+num[i][j])//鏃犻渶鎷呭績涓嶆槸浠庡乏涓婃柟鍒板彸涓嬫柟錛屽洜涓鴻嫢i<j錛宺esult[][]璧嬩負浜嗚礋鏃犵┓
                                               result[i][j]=result[i-1][k]+num[i][j]
鏇磋緇嗙殑浠g爜鍙互鍒拌嫃寮虹殑鍗氬http://download.csdn.net/user/china8848/鑾峰緱

luis 2009-07-14 10:05 鍙戣〃璇勮
]]>
poj 1631 Bridging signals 緇忓吀dp 鏃墮棿澶嶆潅搴lognhttp://www.shnenglu.com/luyulaile/archive/2009/07/12/89869.htmlluisluisSun, 12 Jul 2009 07:46:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/12/89869.htmlhttp://www.shnenglu.com/luyulaile/comments/89869.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/12/89869.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/89869.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/89869.html

鎶宸э細璁劇疆涓涓暟緇刟[i]

瀛樻斁鎵鏈夐暱搴︿負i鐨勪笂鍗囧瓙搴忓垪涓渶灝忕殑鏈厓绱犲鹼紝姣斿璇村彧鏈変袱涓暱搴︿負3鐨勪笂鍗囧瓙搴忓垪123鍜?24錛岄偅涔坅[3]涓瓨鏀劇殑灝辨槸3錛堟湯鍏冪礌3<4錛?/p>

閭d箞褰撴潵涓涓柊鏁癲ata鏃訛紝濡傛灉瀹冪殑鍊煎ぇ浜庢渶闀塊暱搴︾殑鏈厓绱犵殑鍊鹼紙鍗砤[ans]錛夛紝鍒檃ns++錛涗笖a[ans]=data;

鍚﹀垯錛岄氳繃浜屽垎鏌ユ壘錛堟暟緇刟涓殑鍏冪礌涓洪掑錛夛紝灝嗘渶鎺ヨ繎data涓斿ぇ浜巇ata鐨勯偅涓厓绱犳洿鏂頒負data錛屾棦鏈灝忕殑澶т簬瀹冪殑鏁般?br>渚嬪1,5,3,4,涔嬪悗鏉ヤ釜2錛宎[1]=1,a[2]=3,a[3]=4;鍒欐洿鏂癮[2]=2;
鐢變簬浜屽垎鏌ユ壘澶嶆潅搴︿負log(n)錛屽鍥翠負n,鎬葷殑澶嶆潅搴︿負nlogn

浠g爜銆?
#include <stdio.h>
int res[40000];
int binSearch(int left, int right, int num)//鎵懼埌鏈灝忕殑澶т簬絳変簬瀹冪殑鏁?nbsp;
{
    
while(left <= right)
    {
        
int mid=(left + right)/2;
         
if(res[mid]<num)
            left
=mid+1;
        
else
            right
=mid-1;
    }
    
return right;
}

int main()
{
 
//freopen("s.txt","r",stdin);
 
// freopen("key.txt","w",stdout);
    int t, n, num;
    scanf(
"%d"&t);
    
while(t--)
    {
        scanf(
"%d %d"&n, &num);
        res[
0]=num;
        
int tot = 1;
        
for(int i=1;i<n;++i)
        {
            scanf(
"%d"&num);
            
if(num>=res[tot-1])
            res[tot
++]=num;
            
else
            {
                
int pos=binSearch(0,tot-1,num);//鎵懼埌鏈灝忕殑澶т簬瀹冪殑鏁?nbsp;
                res[pos+1= num;
            }   
        }
        printf(
"%d\n", tot);
    }
    
return 0;
}


luis 2009-07-12 15:46 鍙戣〃璇勮
]]>
joj 1092 To the Max 杞笘Dp緇忓吀http://www.shnenglu.com/luyulaile/archive/2009/07/09/89674.htmlluisluisThu, 09 Jul 2009 10:37:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/07/09/89674.htmlhttp://www.shnenglu.com/luyulaile/comments/89674.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/07/09/89674.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/89674.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/89674.html[鍘熷垱]POJ1050 To the Max 瑙i鎶ュ憡
2006-04-17 11:55
棰樼洰澶ф剰:

璇誨叆涓涓猲*n鐨勬暟緇?姣斿 

0 -2 -7 0 

9 2 -6 2 

-4 1 -4 1 

-1 8 0 -2  

浠庨噷闈換鎰忔埅鍙栦竴涓煩闃?浣垮緱鐭╅樀鎵鍖呭惈鐨勬暟瀛楃殑鍜屾渶澶?

鎴彇鍑烘潵鐨勭煩闃?鍜屼負15

9 2 

-4 1 

-1 8 

---------------------------------------------------------

POJ 1050 鎴戠殑瑙i鎶ュ憡錛?br>
榪欎釜棰樼洰寰堢粡鍏哥殑璇達紝O錛圢^3錛夌殑DP銆?br>
棣栧厛鍋朵滑鑰冨療榪欐牱鐨勯鐩紝綆鍖栫増錛?br>
宸茬煡涓鍒楁暟錛屾眰浠繪剰榪炵畫鑻ュ共涓暟鍜岀殑鏈澶у箋?br>
SAMPLE錛?nbsp;3 2 -6 2 -1 7

鍘熸暟3        2      -6       2      -1       7 

澶勭悊3        5      -1       2       1       8

鍥犱負鏄繛緇嫢騫蹭釜鑷劧鏁扮殑鍜岋紝閭d箞錛屽墠闈㈢殑鏌愪釜鏁板瓧鍙栦笌涓嶅彇鐨勬潯浠跺湪浜庯細浠ュ墠闈㈣繖涓暟瀛椾負緇撳熬鐨勮繛緇暟鐨勫拰鏈澶у兼槸鍚﹀ぇ浜?錛屽鏋滃ぇ浜?錛岄偅涔堣繖涓暟瀛楀繀鐒惰浼氬嚭鐜板湪鍖呮嫭鏁板瓧鐨勫簭鍒椾腑錛屽惁鍒欐棤娉曞仛鍒版渶澶с?br>
鎵浠ワ紝鏄劇劧銆傚鐞嗙殑鍘熷垯鏄痬axn[i]=max{0,maxn[i-1]}+a[i];

鐢變簬鏃犻』璁板綍浣嶇疆銆傛墍浠ワ紝鍙互鐩存帴鐢ㄤ竴涓彉閲弒um浠f浛maxn鏁扮粍銆侽(n)鐨勬壂鎻忓嵆鍙?br>
鍗曞垪鏁板瓧鐨勯棶棰樿В鍐充簡錛屼笅闈㈡垜浠冨療澶氬垪鏁板瓧鐨?br>
sample:

         0    -2    -7    0 

         9     2    -6    2 

        -4     1    -4    1 

        -1     8     0   -2 



鎴戜滑鍙互灝嗗鍒楁暟瀛楄漿鎹㈡垚鍗曞垪鏁板瓧鏉ュ仛錛?nbsp;鍙互榪欐牱璁炬兂錛岀粨鏋滄槸涓涓暱鏂瑰艦錛屾垜浠妸浠栧帇鎵侊紝浣垮緱瀹戒負1銆?br>
寮曞叆杈呭姪鏁扮粍st,st[i][j]浠h〃絎琲鍒椾粠絎?琛屽紑濮嬬殑鏁板瓧绱姞鍒扮j琛岀殑鍊箋傞偅涔堬紝鎴戜滑姣忔鍘嬫墎鐨勬椂鍊欙紝灝卞彲浠ョ敤st[i][j]-st[i][k-1]鏉ヨ〃紺虹i鍒椾粠絎琸涓暟瀛楃瘡鍔犲埌絎琷涓暟瀛楃殑鍊箋傝揪鍒板帇緙╃殑鏁堟灉銆傜劧鍚庣敤涓婇潰鍗曞垪鏁板瓧鐨勬柟娉曟潵鍋氥傜畻娉曟椂闂村鏉傚害O (N^3)

Source



Problem Id:1050  User Id:galaxy 

Memory:112K  Time:0MS

Language:G++  Result:Accepted



/*

  Name:POJ 1050 

  Copyright: flymouse@galaxy                                         

  Author:chenlei

  Date: 15-02-06 07:36

  Description: DP O(N^3)

*/

#include <stdio.h>

#include <string.h>

#define mt 101

int main()

{

int a[mt][mt];

int st[mt][mt];

int p,k,n,i,j,sum,maxn;

//freopen("in.txt","r",stdin);

scanf("%d",&n);

for (i=1;i<=n;i++)

for (j=1;j<=n;j++)

scanf("%d",&a[i][j]);

memset(st,0,sizeof(st));

for (i=1;i<=n;i++)

   for (j=1;j<=n;j++)

  st[i][j]=st[i][j-1]+a[j][i];

  maxn=0;

   for (i=1;i<=n;i++)

   {

for (j=i;j<=n;j++)

{

p=st[1][j]-st[1][i-1];

sum=p;

for (k=2;k<=n;k++)

{

if (sum>0)

sum+=st[k][j]-st[k][i-1];

else sum=st[k][j]-st[k][i-1];

if (sum>p) p=sum;

}

if (p>maxn) maxn=p;

}

   }

   printf("%d\n",maxn);

   return 0;
鍘熸枃鍦板潃錛?a >http://hi.baidu.com/flymouse/blog/item/fd1378f05c7ff7c37931aac3.html


luis 2009-07-09 18:37 鍙戣〃璇勮
]]>
joj 1995: Energy 姹傝繛緇瓙涓蹭嬌鍜屾渶澶?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 04 Jul 2009 01:27:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/89209.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/89209.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/89209.html</trackback:ping><description><![CDATA[<p>Energy</p> <hr> <p> <table cellSpacing=3 cellPadding=3 width="75%" border=1> <colgroup style="COLOR: red; TEXT-ALIGN: center" span=7> <tbody> <tr> <th height=40>Status</th> <th>In/Out</th> <th>TIME Limit</th> <th>MEMORY Limit</th> <th>Submit Times</th> <th>Solved Users</th> <th>JUDGE TYPE</th> </tr> <tr> <td align=middle height=40><span id=probinfo_placeholder><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></span></td> <td>stdin/stdout</td> <td>3s</td> <td>10240K</td> <td>717</td> <td>196</td> <td>Standard</td> </tr> </tbody> </table> </p> <div id="m0e0ssk" class=prob_text> <p>Mr. Jojer is a very famous chemist. He is doing a research about behavior of a group of atoms. Atoms may have different energy and energy can be positive or negative or zero, e.g. 18 or -9. Absolute value of energy can not be more than 100. Any number of continuous atoms can form an atom-group. Energy of an atom-group is defined by the sum of energy of all the atoms in the group. All the atoms form an atom-community which is a line formed by all the atoms one by one. Energy of an atom-community is defined by the greatest energy of an atom-group that can be formed by atoms in the atom-community. The problem is, given an atom-community, to calculate its energy.</p> <h3>Input</h3> <p>The input contains several test cases. Each test case consists of two lines describing an atom-community. The first line of each test case contains an integer N(N<=1000000), the number of atoms in the atom-community. The second line of each test case contains N integers, separated by spaces, each representing energy of an atom, given in the order according to the atom-community. The last test case marks by N=-1, which you should not proceed.</p> <h3>Output</h3> <p>For each test case(atom-community description), print a single line containing the energy.</p> <h3>Sample Input</h3> <pre>5 8 0 6 4 -1 -1</pre> <h3>Sample Output</h3> <pre>18</pre> </div> <p><br>鐞嗚В棰樻剰寰堥噸瑕侊紝棰樼洰鐨勬剰鎬濇槸璇?鍦╩涓腑閫?nbsp;  榪炵畫鐨刵涓猘tom鑳介噺鍊?浣垮叾鏈澶с?br>紼嬪簭涓璼umtemp錛宻um銆俿umtemp紜畾鐨勬槸鍏跺乏杈圭晫錛宻um紜畾鍏跺彸杈圭晫銆?br>sumtemp紜畾宸﹁竟鍓峮涓暟涔嬪拰涓鴻礋鐨勬渶澶х殑n錛屼笖絎琻涓暟鏄劇劧涓鴻礋錛岀劧鍚庝粠n+1寮濮嬮夋暟銆?br>sum紜畾浜嗗彸杈圭晫浣垮叾鏈澶с?br>姹傚拰鏈澶ч兘鍙互鐢ㄨ繖縐嶆濊礬錛侊紒錛侊紒錛侊紒錛侊紒錛侊紒<br>涓句緥<br>1錛?錛?4錛?錛?錛?2錛?錛?錛?6錛?錛?3錛?錛?0<br>璇風湅sumt1=1,sum=1<br>sumt2=2;sum=1+2=3;<br>sum3=sum2-4=-1;鍒檚umtemp=0;sum涓嶅彉銆?br>sum4=sumtemp+4;sum<sum4,sum=4;<br>sum5=sumtemp+2錛泂um<sum5,sum=6<br>鎬諱箣sum鍙湁鍦╯um<sumtemp鏃舵墠淇敼銆俿umtemp<0鍒欐竻0.<br>涓緇磀p.<br>#include"stdio.h"<br>int main()<br>{<br> freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br> int n;<br> int a;<br> while(scanf("%ld",&n),n!=-1)<br> {  <br>      long long  sum=-0x7fffffff,sumtemp=-0x7fffffff;<br>   for(long i=0;i<n;i++)<br>   { <br>    scanf("%d",&a);<br>    if(sumtemp>0)<br>   sumtemp+=a;<br>    else<br>   sumtemp=a;<br>    if(sumtemp>sum)<br>   sum=sumtemp;</p> <p>   }<br>   printf("%lld\n",sum);</p> <p> }<br> return 0;<br>}</p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/89209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-04 09:27 <a href="http://www.shnenglu.com/luyulaile/archive/2009/07/04/89209.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>搴忓伓瀵圭敓鎴愭硶涓縐嶈〃鐜板艦寮?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Thu, 02 Jul 2009 08:05:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/89086.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/89086.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/89086.html</trackback:ping><description><![CDATA[<p>Tug of War</p> <hr> <p> <table cellSpacing=3 cellPadding=3 width="75%" border=1> <colgroup style="COLOR: red; TEXT-ALIGN: center" span=7> <tbody> <tr> <th height=40>Status</th> <th>In/Out</th> <th>TIME Limit</th> <th>MEMORY Limit</th> <th>Submit Times</th> <th>Solved Users</th> <th>JUDGE TYPE</th> </tr> <tr> <td align=middle height=40><span id=probinfo_placeholder><img height=20 src="http://acm.jlu.edu.cn/joj/images/ok1.gif" width=20></span></td> <td>stdin/stdout</td> <td>15s</td> <td>8192K</td> <td>479</td> <td>114</td> <td>Standard</td> </tr> </tbody> </table> </p> <div id="ke0uq8q" class=prob_text>A tug of war is to be arranged at the local office picnic. For the tug of war, the picnickers must be divided into two teams. Each person must be on one team or the other; the number of people on the two teams must not differ by more than 1; the total weight of the people on each team should be as nearly equal as possible. <p>The first line of input contains <em>n</em> the number of people at the picnic. <em>n</em> lines follow. The first line gives the weight of person 1; the second the weight of person 2; and so on. Each weight is an integer between 1 and 450. There are at most 100 people at the picnic. <p>The input may contain several test cases. <p>Your output will be a single line containing 2 numbers: the total weight of the people on one team, and the total weight of the people on the other team. If these numbers differ, give the lesser first. <h3>Sample Input</h3> <pre>3 100 90 200 </pre> <h3>Output for Sample Input</h3> <pre>190 200 </pre> </div> <p><br>鍒╃敤dp鎬濇兂 錛宯涓哄伓鏁版椂姹傚嚭s(n,n/2)錛宯涓哄鏁版椂 涔熸槸s(2n,n/2)錛屽拰sum/2鏈鎺ヨ繎鐨勯偅涓傞潪甯哥粡鍏哥殑鎬濊礬銆?br>S(k, 1) = {A[i] | 1<= i <= k}<br>S(k, k) = {A[1]+A[2]+…+A[k]}<br>S(k, i) = S(k-1, i) U {A[k] + x | x灞炰簬S(k-1, i-1) }<br>//涓涓嬩唬鐮佸彧鑳界敤浜巗um鐗瑰埆灝忕殑鎯呭喌錛屽惁鍒欎細瓚呮椂錛侊紒錛侊紒錛侊紒錛侊紒錛侊紒錛?br>#include<iostream><br>#include<cstdlib><br>#define MAX 101 <br>#define min(a,b) ((a)<(b) ? (a) : (b))<br>using namespace std;</p> <p>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  int num;<br>  int a[MAX],i,j,k,l,m,NUM;<br>  bool s[MAX][2500];<br>  while(cin>>num)<br>  {<br>  int sum=0;<br>    for(i=1;i<=num;i++)<br>   {<br>  cin>>a[i];<br>  sum+=a[i]; <br>   }<br>   if(num%2==0)NUM=num/2;<br>   else NUM=num/2+1;</p> <p>    for(i=0;i<=num;i++)<br>     for(j=0;j<=sum/2;j++)<br>      s[i][j]=false;//琛ㄧず鍙杋涓墿鍝佽兘鍚﹁揪鍒伴噸閲忔槸j. <br>      <br>   s[0][0]=true;<br>   for(k=1;k<=num;k++)//蹇呴』鍦ㄦ渶澶栧眰錛屽厓绱犱笉鑳介噸澶?<br>   for(j=min(k,NUM);j>=1; j--)//閫掑噺鐨勭粨鏋滄槸浣垮緱涓嶄細鍑虹幇鍦ㄥ悓涓灞傛鐨勪簰涓哄洜鏋?銆併併併併併併併併併併佸閥濡欑殑瀹炵幇浜嗚鏈笂鐨勫簭鍋跺鐢熸垚娉曘?br>   for(i=a[k];i<=sum/2;i++)<br>   {<br>  if(s[j-1][i-a[k]])<br>  s[j][i]=true;<br> }<br> <br> for(i=sum/2; i>=0; i--) {   <br>    if(s[NUM][i]) {   <br>        cout <<i<<" "<<sum-i<<endl;   <br>        break;   <br>    }   <br>}  </p> <p>  }<br>  //system("PAUSE");<br>  return   0;<br>  }<br>涓嬩竴嬈″疄鐜頒竴涓簭鍋剁敓鎴愭硶銆?/p> <p>#include <iostream><br>#include <functional><br>using namespace std;</p> <p>int a[101];<br>bool b[101][45002];</p> <p>int main(){<br>// freopen("s.txt","r",stdin);<br>//  freopen("key.txt","w",stdout);<br>    int N,M,i,j,k;<br>    while(scanf("%d",&N)!=EOF){<br>         memset(b,0,sizeof(b));<br>         a[0]=M=0;<br>        for(i=1;i<=N;i++){<br>             scanf("%d",a+i);<br>             M+=a[i];<br>         }<br>         b[0][0]=1;<br>        for(k=1;k<=N;k++){<br>            for(i=1;i<=N/2;i++){<br>                for(j=M/2;j>=0;j--){<br>                    if(b[i-1][j]){<br>                         b[i][j+a[k]]=1;<br>                     }<br>                 }<br>             }<br>         }<br>        for(i=M/2,j=M/2+1;i>=0;i--,j++){<br>            if(b[N/2][i]){<br>                 printf("%d %d\n",i,M-i);<br>                break;<br>             }<br>            if(b[N/2][j]){<br>                 printf("%d %d\n",M-j,j);<br>                break;<br>             }<br>         }<br>     }<br>    return 0;<br>}<br></p> <img src ="http://www.shnenglu.com/luyulaile/aggbug/89086.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-07-02 16:05 <a href="http://www.shnenglu.com/luyulaile/archive/2009/07/02/89086.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>joj 2521 Monkey and fruits 鐭沖瓙鍚堝茍闂http://www.shnenglu.com/luyulaile/archive/2009/06/30/88932.htmlluisluisTue, 30 Jun 2009 13:01:00 GMThttp://www.shnenglu.com/luyulaile/archive/2009/06/30/88932.htmlhttp://www.shnenglu.com/luyulaile/comments/88932.htmlhttp://www.shnenglu.com/luyulaile/archive/2009/06/30/88932.html#Feedback0http://www.shnenglu.com/luyulaile/comments/commentRss/88932.htmlhttp://www.shnenglu.com/luyulaile/services/trackbacks/88932.htmlAfter culling his most favorite fruits from the trees in an orchard,Keen AS, a mischievous monkey, is confused of the way in which he can combine these piles of fruits into one in the most laborsaving manner. Each turn he can merely combine any two piles into a larger one. Obviously, by combining N-1 times for N piles of fruits, one pile results eventually. It always takes AS a certain quantity of units of stamina, which equals to the sum of the amounts of fruits in each of the two piles combined, to complete a combination. For instance, given three piles of fruits, containing 1, 2, and 9 fruits respectively, the combination of 1 and 2 would cost 3=1+2 units of stamina, and two piles-3 and 9-are resulted; finally, combining them would cost another 12=3+9 units of stamina, and the total units of stamina taken in the whole procedure is 15=3+12. Surely there are many a possible means to combine these three piles; however, it can be proved that 15 is the minimum amount of units of stamina in demand, and that is what your program is required to do. in this problem ,the fruits are put in a strait line. A pile of fruits 'P' can only combined with the rightest pail on the left of P or the leftest on the right of P, and the united pile will at the position of the bigger one.

Input

The input file consists of many test cases. The first line contains an integer N (<=100), indicating the number of piles, and the second line contains N integers, each of which represents the amount of fruits in a pile. no integer will more than 10000, the sequence of integer also means the location of the piles.

Output

Your program should print the minimum amount of units of stamina that are required to combine these piles of fruits into one on request.

Sample Input

3
1 2 9

Sample Output

15

鍏稿瀷鐨勭煶瀛愬悎騫墮棶棰樸?br>#include<stdio.h>
int a[101][101],sum[101];
int stone[101];
int main()
{
    int n,i,j,k,flag,l,t;
    while(scanf("%d",&n)!=EOF)
    {
        for(i=1;i<=n;i++)
        scanf("%d",&stone[i]);
        sum[0]=0;
        for(i=1;i<=n;i++)
        {
            sum[i]=sum[i-1]+stone[i];      
            a[i][i]=0;
        }
        for(l=1;l<=n-1;l++)
        for(i=1;i<=n-l;i++)
        {
            flag=0;
            j=i+l;
            for(k=i;k<j;k++)                              
            {
                t=a[i][k]+a[k+1][j]+sum[j]-sum[i-1];
                if(!flag)
                {
                    flag=1;
                    a[i][j]=t;
                }
                else if(t<a[i][j])
                a[i][j]=t;
            }
        }
        printf("%d\n",a[1][n]);
    }
    return 0;
}


luis 2009-06-30 21:01 鍙戣〃璇勮
]]>
joj 1026 鍔ㄦ佽鍒掞紝鐢熸垚鍑芥暟鍙婃敼榪?/title><link>http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html</link><dc:creator>luis</dc:creator><author>luis</author><pubDate>Sat, 27 Jun 2009 02:44:00 GMT</pubDate><guid>http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html</guid><wfw:comment>http://www.shnenglu.com/luyulaile/comments/88628.html</wfw:comment><comments>http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/luyulaile/comments/commentRss/88628.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/luyulaile/services/trackbacks/88628.html</trackback:ping><description><![CDATA[<div id="0oma0y0" class=prob_text> <p>One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:</p> <p align=center><img height=163 src="http://acm.jlu.edu.cn/joj/images/problems/1026.gif" width=623> </p> <p align=left>Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.</p> <br> <h3>Input</h3> Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input. <p> </p> <p> </p> <br> <h3>Output</h3> Numbers Q, one on each line. <p> </p> <br> <h3>Sample Input</h3> <pre>3 5 0 </pre> <h3>Sample Output</h3> <pre>1 2 </pre> 鏂規硶1錛屽姩鎬佽鍒?br><br>#include<iostream><br>#include<cstdlib><br>using namespace std;<br>  int main()<br>  {<br>  freopen("s.txt","r",stdin);<br>  freopen("key.txt","w",stdout);<br>  double f[501][501]={0};<br>  double s;<br>  int i,j,k,n;<br>  for(i=3;i<=500;i++)<br>  for(j=1;j<=(i-1)/2;j++)<br>    f[i][j]=1;<br>  for(i=3;i<=500;i++)<br>    for(j=1;j<=(i-1)/2;j++)<br>    {<br> for(k=j+1;k<=(i-j-1)/2;k++)<br>   f[i][j]=f[i-j][k]; <br> }<br>    while(scanf("%d",&n),n) { <br>        s=0; <br>        for(i=1;i<=(n-1)/2;i++) s+=f[n][i]; //f[n]=f[n][1]+f[n][2]+-----+f[n][floor((i-1)/2)]<br>        printf("%.0f\n",s); <br>    } <br>  //system("PAUSE");<br>  return   0;<br>  }<br>鏇村鐨勬柟娉曪細鐢熸垚鍑芥暟娉?br>璁$畻(1+x)(1+x^2)(1+x^3)-----,x^n鐨勭郴鏁板嵆涓烘墍姹?br>int i,j;<br>double ans[510]={1,1};//宸茬粡鎶奱ns[1]鍜宎ns[0]璧嬩負1浜嗭紝鍏朵綑涓?<br> for(i=2;i<=500;i++) {   <br>        for(j=500;j>=0;j--) {  <br>            if(i+j<=500) ans[i+j]+=ans[j]; <br>        }  <br>    }  <br><br>鍏堣綆?1+x)(1+x^2)<br>鍐嶈綆?1+x)(1+x^2)   *(1+x^3)<br></div> <img src ="http://www.shnenglu.com/luyulaile/aggbug/88628.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/luyulaile/" target="_blank">luis</a> 2009-06-27 10:44 <a href="http://www.shnenglu.com/luyulaile/archive/2009/06/27/88628.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.shnenglu.com/" title="精品视频久久久久">精品视频久久久久</a> <div class="friend-links"> </div> </div> </footer> <a href="http://www.caikuaipeixun.com.cn" target="_blank">久久久久久久99精品免费观看</a>| <a href="http://www.4fp5r8p.cn" target="_blank">99久久精品免费观看国产</a>| <a href="http://www.czzdjsj.cn" target="_blank">亚洲午夜久久久久妓女影院</a>| <a href="http://www.klzp.net.cn" target="_blank">国产伊人久久</a>| <a href="http://www.par354.cn" target="_blank">成人资源影音先锋久久资源网</a>| <a href="http://www.xibeiguangdian.cn" target="_blank">久久亚洲精品国产精品婷婷</a>| <a href="http://www.9r6.com.cn" target="_blank">久久er国产精品免费观看8</a>| <a href="http://www.ciao-surveys.cn" target="_blank">久久99国产精品二区不卡</a>| <a href="http://www.168sf.com.cn" target="_blank">91精品国产高清91久久久久久</a>| <a href="http://www.jfjn.net.cn" target="_blank">99蜜桃臀久久久欧美精品网站</a>| <a href="http://www.up598.cn" target="_blank">午夜精品久久久久</a>| <a href="http://www.qsstudio.cn" target="_blank">久久亚洲sm情趣捆绑调教</a>| <a href="http://www.jiaotongpai.cn" target="_blank">久久乐国产综合亚洲精品</a>| <a href="http://www.zhxyzb.cn" target="_blank">久久国产色av免费看</a>| <a href="http://www.tafeemanager.cn" target="_blank">久久人人爽人人爽人人片AV麻烦</a>| <a href="http://www.buksk.cn" target="_blank">久久久精品国产免大香伊</a>| <a href="http://www.gcjszzbjb.cn" target="_blank">日产精品久久久久久久</a>| <a href="http://www.yue88.cn" target="_blank">国内精品久久久久久久久电影网</a>| <a href="http://www.esog.com.cn" target="_blank">一本久道久久综合狠狠爱</a>| <a href="http://www.iteethle.cn" target="_blank">无码精品久久久久久人妻中字</a>| <a href="http://www.jiawengc.cn" target="_blank">久久精品麻豆日日躁夜夜躁</a>| <a href="http://www.qdyshl.cn" target="_blank">久久99国产精品二区不卡</a>| <a href="http://www.svelan.cn" target="_blank">99久久精品免费看国产</a>| <a href="http://www.shangxuewenhua.cn" target="_blank">久久久免费观成人影院</a>| <a href="http://www.saxie.cn" target="_blank">久久久久久久波多野结衣高潮</a>| <a href="http://www.shequjingying.cn" target="_blank">一本久久a久久精品亚洲</a>| <a href="http://www.shangtoo.cn" target="_blank">国产麻豆精品久久一二三</a>| <a href="http://www.twhx.org.cn" target="_blank">久久精品国产亚洲沈樵</a>| <a href="http://www.coubu.cn" target="_blank">欧美久久综合九色综合</a>| <a href="http://www.waihuimaoyi.cn" target="_blank">97精品依人久久久大香线蕉97</a>| <a href="http://www.tongshenghu.com.cn" target="_blank">久久久久久国产精品免费无码</a>| <a href="http://www.essledyntp.com.cn" target="_blank">国产精品久久精品</a>| <a href="http://www.ezchem.cn" target="_blank">亚洲精品美女久久久久99小说</a>| <a href="http://www.95dq.cn" target="_blank">午夜欧美精品久久久久久久</a>| <a href="http://www.92dyy.cn" target="_blank">青青青伊人色综合久久</a>| <a href="http://www.07sn.cn" target="_blank">日本国产精品久久</a>| <a href="http://www.3171unp.cn" target="_blank">久久久久久久久久久久中文字幕</a>| <a href="http://www.e8ux.cn" target="_blank">久久99精品国产麻豆不卡</a>| <a href="http://www.lafei-pingtai.cn" target="_blank">久久久久久精品免费免费自慰</a>| <a href="http://www.114best.com.cn" target="_blank">欧美777精品久久久久网</a>| <a href="http://www.jn879.cn" target="_blank">人妻无码精品久久亚瑟影视</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>