poj 1579 Function Run Fun

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   使用   ar   strong   

題目連結:http://poj.org/problem?id=1579

 

思路:

        題目給出遞迴公式,使用動態規劃的記憶搜尋即可解決。

代碼:

 

#include <stdio.h>#include <string.h>const int MAX_N = 20 + 5;int dp[MAX_N][MAX_N][MAX_N];int w( int a, int b, int c ){    if ( dp[a][b][c] != -1 )        return dp[a][b][c];    if ( a <= 0 || b <= 0 || c <= 0 )        return dp[a][b][c] = 1;    else    if ( a < b && b < c )        return dp[a][b][c] = w(a, b, c-1) + w(a, b-1, c-1) - w(a, b-1, c);    else        return dp[a][b][c] = w( a-1, b, c) + w( a-1, b-1, c) +                w( a-1, b, c-1 ) - w( a-1, b-1, c-1);}int main(){    int a, b, c;    int ans = 0;    while ( scanf( "%d %d %d", &a, &b, &c ) != EOF )    {        if ( a == -1 && b == -1 && c == -1 )            break;        memset( dp, -1, sizeof(dp) );        if ( a <= 0 || b <= 0 || c <= 0 )            ans = 1;        else        if ( a > 20 || b >20 || c > 20 )            ans = w(20, 20, 20);        else            ans = w(a, b, c);        printf( "w(%d, %d, %d) = %d\n", a, b, c, ans );    }    return 0;}

 

poj 1579 Function Run Fun

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.