HDOJ 1579 Function Run Fun

动态规划~~~

题目地址:

http://acm.hdu.edu.cn/showproblem.php?pid=1579

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 // Author: Tanky Woo
// HDOJ 1579
 
#include <iostream>
#include <string.h>
using namespace std;
int fun[21][21][21];
 
int main()
{
    for(int i=0; i<=20; ++i)
        for(int j=0; j<=20; ++j)
        {
 
            fun[0][i][j] = 1;
            fun[i][0][j] = 1;
            fun[i][j][0] = 1;
        }
    for(int i=1; i<=20; ++i)
        for(int j=1; j<=20; ++j)
            for(int k=1; k<=20; ++k)
            {
                if(i<j && j<k)
                    fun[i][j][k] = fun[i][j][k-1] + fun[i][j-1][k-1] - fun[i][j-1][k];
                else
                    fun[i][j][k] = fun[i-1][j][k] + fun[i-1][j-1][k] + fun[i-1][j][k-1]-fun[i-1][j-1][k-1];
 
            }
    int a, b, c;
    while(scanf("%d %d %d", &a, &b, &c) && !(a==-1 && b==-1 && c==-1))
    {
        if(a<=0 || b <= 0 || c<=0)
            printf("w(%d, %d, %d) = 1\n", a, b, c);
        else if(a > 20 || b > 20 || c > 20)
            printf("w(%d, %d, %d) = %d\n",a, b, c, fun[20][20][20]);
        else
            printf("w(%d, %d, %d) = %d\n",a, b, c, fun[a][b][c]);
    }
    return 0;
}

发布者

Tanky Woo

Tanky Woo,[个人主页:https://tankywoo.com] / [新博客:https://blog.tankywoo.com]

《HDOJ 1579 Function Run Fun》有316个想法

发表评论

电子邮件地址不会被公开。 必填项已用*标注