Topic Link: Click to open the link
Problem Solving Ideas:
On the first of the n is 1, 2, 3, 4 of the situation is roughly listed, found n = = 1 o'clock results for 2,n== 2 o'clock results of 2,n = = 3 o'clock results for 4,n== 4 o'clock result is 6.
So bold conjecture ans[i] = ans[i-1] + ans[i-2], but WA in #12. The preprocessing table out to see ... When N reaches 45, the result overflows, and the question long long does not exist, decisive open unsigned long long.
Full code:
#include <algorithm> #include <iostream> #include <cstring> #include <climits> #include < cstdio> #include <string> #include <cmath> #include <map> #include <queue>using namespace std ; typedef long long ll;const int MOD = int (1e9) +7;const int INF = 0x3f3f3f3f;const double EPS = 1e-9;const double PI = ACOs (-1.0); M_pi;int n;const int maxn = 55;unsigned Long Long ans[maxn];int main () { #ifdef doubleq freopen ("In.txt", "R", stdin); #endif Std::ios::sync_with_stdio (false); Std::cin.tie (0); ANS[1] = ans[2] = 2; for (int i = 3; i < MAXN; i + +) ans[i] = ans[i-1] + ans[i-2]; while (CIN >> N) { cout << ans[n] << Endl; }}
More highlights please visit: Click to open the link
Ural1225 (mathematics)