Ural1225 (mathematics)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.