• Codeforces Round #818 (Div. 2)


    D. Madoka and The Corruption Scheme

    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    Madoka decided to entrust the organization of a major computer game tournament "OSU"!

    In this tournament, matches are held according to the "Olympic system". In other words, there are 2^n participants in the tournament, numbered with integers from 1 to 2^n. There are nn rounds in total in the tournament. In the ii-th round there are 2^n−i matches between two players (one of whom is right, the other is left), after which the winners go further along the tournament grid, and the losing participants are eliminated from the tournament. Herewith, the relative order in the next round does not change. And the winner of the tournament — is the last remaining participant.

    But the smaller the participant's number, the more he will pay Madoka if he wins, so Madoka wants the participant with the lowest number to win. To do this, she can arrange the participants in the first round as she likes, and also determine for each match who will win — the participant on the left or right.

    But Madoka knows that tournament sponsors can change the winner in matches no more than k times. (That is, if the participant on the left won before the change, then the participant on the right will win after the change, and if the participant on the right won, then the participant on the left will win after the change).

    So, the first image shows the tournament grid that Madoka made, where the red lines denote who should win the match. And the second one shows the tournament grid, after one change in the outcome of the match by sponsors (a match between 1 and 3 players).

    Print the minimum possible number of the winner in the tournament, which Madoka can get regardless of changes in sponsors. But since the answer can be very large, output it modulo 109+7. Note that we need to minimize the answer, and only then take it modulo.

    Input

    The first and the only line contains two integers nn and kk (1≤n≤10^5,1≤k≤min(2^n−1,10^9)) — the number of rounds in the tournament and the number of outcomes that sponsors can change.

    Output

    Print exactly one integer — the minimum number of the winner modulo 109+71

    Examples

    input

    1 1
    

    output

    2
    

    input

    2 1
    

    output

    3
    

    input

    3 2
    

    output

    7
    

    Note

    In the first example, there is only one match between players 1 and 2, so the sponsors can always make player 2 wins.

    The tournament grid from the second example is shown in the picture in the statement.

     

     

    可能二叉树还有这个性质吧。

    就不如说n=3,我如果叶子节点到根节点有两条没通,其实是一个组合数

    类似下面我画的这个图。 

     7:100

    6:010

    4:001

    它是一个排列,你把坐标换成7、6、5就行。

    1. #include<bits/stdc++.h>
    2. using namespace std;
    3. typedef long long ll;
    4. const int mod=1e9+7;
    5. const int N=1e6+10;
    6. ll f[N],ivf[N];
    7. ll ksm(ll x,ll n)
    8. {
    9. ll res=1;
    10. while(n)
    11. {
    12. if(n&1)res=res*x%mod;
    13. x=x*x%mod;
    14. n>>=1;
    15. }
    16. return res;
    17. }
    18. void init()
    19. {
    20. f[0]=1;
    21. for(int i=1; i<=1e6; i++) f[i]=1ll*f[i-1]*i%mod;
    22. int m=1e6;
    23. ivf[m]=ksm(f[m],mod-2);
    24. for(int i=m-1; i>=0; i--)
    25. {
    26. ivf[i]=1ll*ivf[i+1]*(i+1)%mod;
    27. }
    28. }
    29. ll C(ll n,ll m)
    30. {
    31. return 1ll*f[n]*1ll*ivf[m]%mod*ivf[n-m]%mod;
    32. }
    33. void solve()
    34. {
    35. int n,k;
    36. cin>>n>>k;
    37. if(k>=n)
    38. {
    39. cout<<ksm(2,n)%mod;
    40. return;
    41. }
    42. else
    43. {
    44. ll ans=0;
    45. for(int i=0; i<=min(n,k); i++)
    46. {
    47. ans=(ans+C(n,i)%mod)%mod;
    48. }
    49. cout<<ans;
    50. return;
    51. }
    52. }
    53. int main()
    54. {
    55. ios::sync_with_stdio(false);
    56. cin.tie(0);
    57. cout.tie(0);
    58. init();
    59. int T;
    60. T=1;
    61. while(T--)
    62. {
    63. solve();
    64. }
    65. return 0;
    66. }

  • 相关阅读:
    Mysql调优(一)——性能监控
    [docker]笔记-网络故障处理
    滑动窗口 解题思路
    randint和randrange的区别
    API接口文档1688阿里巴巴获取跨境属性数据
    Docker使用nodejs镜像构建express服务
    Maya vs Blender:制作3D动画首选哪一个?
    使用skvideo.io.vread读取avi视频,报错“No way to determine width or height from video...”
    Uiautomator项目搭建与实现原理
    R语言dplyr包summarise_at函数计算dataframe数据中多个数据列(通过向量指定)的均值和中位数、指定na.rm参数配置删除缺失值
  • 原文地址:https://blog.csdn.net/m0_61949623/article/details/126679019