UVa 11069 A Graph Problem (斐波那契)
Given an undirected graph of the following form with n nodes, 1 ≤ n ≤ 76:
Your task is to calculate the number of subsets of nodes of the graph with the following properties:
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 the number of subsets as described above on a single line. The number of all subsets will be less than 2^31.
1234530
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;}