Codeforces Round #382 (Div. 1)

Source: Internet
Author: User
Tags time limit
A. Tennis championship time limit per test 2 seconds memory limit per test megabytes input standard input output stand ARD output


Famous Brazil City Rio de Janeiro holds a tennis tournament and Ostap Bender doesn ' t want to miss this event. There would be N players participating, and the tournament would follow knockout rules from the very first game. That's means, that if someone loses a game he leaves the tournament immediately.



Organizers was still arranging tournament grid (i.e. the order games would happen and who was going to play with whom) but T Hey the already fixed one Rule:two players can play against each and only if the number of games one's them has Alrea Dy played differs by no further than one from the number of games the other one has already played. Of course, both players had to win all their games on order to continue participating in the tournament.



Tournament hasn ' t started yet so the audience is a bit bored. Ostap decided to find out what's the maximum number of games the winner of the tournament can take part in (assuming the Rule above is used). However, it's unlikely he can deal with this problem without your help. Input



The only line of the input contains a single integer n (2≤n≤1018)-the number of players to participate in the Tourna ment. Output



Print the maximum number of games in which the winner of the tournament can take part. Examples input


2
Output
1
Input
3
Output
2
Input
4
Output
2
Input
10
Output
4
Note


In all samples We consider this player number 1 is the winner.



In the first sample, there would are only one game so the answer is 1.



In the second sample, Player 1 can consequently beat players 2 and 3.



In the third sample, Player 1 can ' t play with each other player as after he plays with players 2 and 3 he can ' t play again St Player 4, as he has 0 games played, and while player 1 already played 2. Thus, the answer is 2 and to achieve we do pairs (1, 2) and (3, 4) and then clash the winners.



F[n] Indicates how many people a person needs at least to participate in N games.





#include <cstdio>
#include <vector>
#include <iostream>
using namespace std;

typedef long long LL;
ll a[120];

int main ()
{
    ll n;
    A[1] = 2;
    A[2] = 3;
    scanf ("%lld", &n);
    for (int i = 3; i < i++)
    {
        A[i] = a[i-1] + a[i-2];
    }
    for (int i = 1; i < i++)
    {
        if (A[i] > N)
        {
            printf ("%d\n", i-1);
            break;
        }
    }
    return 0;
}

C. Ostap and Tree time limit per test 2 seconds memory limit per test megabytes input standard input output standard o Utput


Ostap already settled down the Rio de Janiero suburb and started to grow a tree in his garden. Recall a tree is a connected undirected acyclic graph.



Ostap ' s tree now has n vertices. He wants to paint some vertices of the tree black such that from any vertex u there are at least one black vertex v at Dist Ance no more than K. Distance between-vertices of the tree is the minimum possible number of edges of the path between them.



As this number of ways to paint the tree can is large, Ostap wants you to compute it modulo 109 + 7. Ways to paint the tree was considered different if there exists a vertex that's painted black in one it's not p Ainted in the other one. Input



The first line of the input contains II integers n and K (1≤n≤100, 0≤k≤min (n-1))-the number of vertices I n Ostap ' s tree and the maximum allowed distance to the nearest black vertex. Don ' t miss the unusual constraint for K.



Each of the next n-1 lines contain-integers UI and VI (1≤ui, vi≤n)-indices of vertices, connected by the i-th Edge. It ' s guaranteed that given graph is a tree. Output



Print One integer-the remainder of division of the number of ways to paint the tree by 1 000 000 007 (109 + 7). Examples input


2 0
1 2
Output
1
Input
2 1
1 2
Output
3
Input
4 1
1 2
2 3
3 4
Output
9
Input
7 2
1 2
2 3
1 4
4 5
1 6
6 7
Output
91
Note


In the first sample, Ostap have to paint both vertices black.



In the second sample, it's enough to paint only one of the vertices, thus the answer are 3:OSTAP can paint only vertex 1, Only vertex 2, vertices 1 and 2 both.



In the third sample, the valid ways to paint vertices is: {1, 3}, {1, 4}, {2, 3}, {2, 4}, {1, 2, 3}, {1, 2, 4}, {1, 3, 4} , {2, 3, 4}, {1, 2, 3, 4}.



Tree Dp,dp[x][j] means x this subtrees tree has a control range of J, J < 0 indicates that the subtrees tree can control-j units, and J > 0 indicates that the subtrees tree requires an outside J unit.








#include <cstdio>
#include <vector>
#include <cstring>
using namespace std;

typedef long long ll;
const int N = 110;
const ll mod = 1000000007;
ll dp[N][N];
int  n, dis;
vector <int> edge[N];

int F(int x)
{
    return x + dis;
}

void dfs(int x, int fa)
{
    ll tmp[N];
    dp[x][F(-dis)] = dp[x][F(1)] = 1;
    for (int i = 0; i < edge[x].size(); i++)
    {
        int u = edge[x][i];
        if (u == fa) continue;
        dfs(u, x);
        memset(tmp, 0, sizeof(tmp));
        for (int a = -dis; a <= dis; a++)
        {
            for (int b = -dis; b <= dis; b++)
            {
                ll num = dp[x][F(a)] * dp[u][F(b)] % mod;
                if (a > 0 && b > 0) 
                {
                    int pos = max(a, b + 1);
                    tmp[F(pos)] = (tmp[F(pos)] + num) % mod;
                }
                else if (a <= 0 && b <= 0)
                {
                    int pos = min(a, b + 1);
                    tmp[F(pos)] = (tmp[F(pos)] + num) % mod;
                }
                else if (a > 0 && b <= 0)
                {
                    int pos = (-b >= a) ? b + 1 : a;
                    tmp[F(pos)] = (tmp[F(pos)] + num) % mod;
                }
                else if (a <= 0 && b > 0)
                {
                    int pos = (-a >= b) ? a : b + 1;
                    tmp[F(pos)] = (tmp[F(pos)] + num) % mod;
                }
            }
        }
        memcpy(dp[x], tmp, sizeof(tmp));
    }
}

int main()
{
    scanf("%d%d", &n, &dis);
    int a, b;
    for (int i = 1; i < n; i++)
    {
        scanf("%d%d", &a, &b);
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    dfs(1, -1);
    ll ans = 0;
    for (int i = 0; i <= dis; i++)
        ans = (ans + dp[1][i]) % mod;
    printf("%lld\n", ans);
    return 0;
}


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.