首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

UVa 11069 A Graph Problem (斐波那契据)

2013-10-22 
UVa 11069 A Graph Problem (斐波那契) A Graph Problem Time limit: 2sGiven an undirected graph of the

UVa 11069 A Graph Problem (斐波那契)

 A Graph Problem 

Time limit: 2s

Given an undirected graph of the following form with n nodes, 1 ≤ n ≤ 76

UVa 11069 A Graph Problem (斐波那契据) 

Your task is to calculate the number of subsets of nodes of the graph with the following properties:

    no nodes in the subset should be connectedit shouldn't be possible to add further nodes to the subset without violating the first conditionFor a graph with 5 nodes the number of subsets which fulfill the above conditions is 4. The subsets are {1,3,5},{2,4},{2,5},{1,4}.

    Input

    The input will consist of a sequence of numbers n,1 ≤ n ≤ 76. Each number will be on a separate line. The input will be terminated by EOF.

    Output

    Output the number of subsets as described above on a single line. The number of all subsets will be less than 2^31.

    Sample input
    1234530

    Sample output
    122344410

    题意:找子集个数, 子集必须满足 元素之差在2-3之间。

    思路:dp,对于第i个元素而言,他可以与他的i-2和i-3元素构成的集合在构成集合,所以dp[i] = dp[i-2] + dp[i - 3];

    代码:

    #include <stdio.h>#include <string.h>int n, dp[77];int main() {    dp[0] = dp[1] = 1; dp[2] = 2;    for (int i = 3; i <= 76; i ++) {dp[i] = dp[i - 3] + dp[i - 2];    }    while (~scanf("%d", &n)) {printf("%d\n", dp[n]);    }    return 0;}


热点排行