• hdu 4602 Partition


    连接:http://acm.hdu.edu.cn/showproblem.php?pid=4602

    题目大意是给你一个数的N的加法构成中另外一个数k的出现次数。如

      4=1+1+1+1
      4=1+1+2
      4=1+2+1
      4=2+1+1
      4=1+3
      4=2+2
      4=3+1
      4=4

    1出现了12次。

    这题是赵鹏搞出来的。一个数N可以分成好N个块,如果说N= 5,K= 2 那么则会有(0|0|0|0|0)0|00|0这样的可以出现或者在边上的情况00|或者|00,才能保证有00会出现,因为122中2出现两次,所以不用怕出现重复的情况。

    代码:

     1 #include<iostream>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<algorithm>
     5 using namespace std;
     6 #define N 1000000007
     7 #define LL __int64
     8 LL mods(LL  a,LL b,LL  n)
     9 {
    10     LL ret=1;
    11     LL tmp=a;
    12     while(b)
    13     {
    14        if(b&0x1) ret=(ret*tmp)%n;
    15        tmp=(tmp*tmp)%n;
    16        b>>=1;
    17     }
    18     return ret;
    19 }
    20 int main()
    21 {
    22     LL  n,k,T;
    23     //freopen("data.in","r",stdin);
    24    // freopen("data.out","w",stdout);
    25     cin>>T;
    26     while(T--)
    27     {
    28         scanf("%I64d%I64d",&n,&k);
    29         if(k > n)
    30         {
    31             printf("0
    ");
    32         }
    33         else
    34         {
    35 
    36             LL ans = 0;
    37             ans = mods(2,n-k,N);
    38             if(n-k-1 >= 1)
    39             ans += mods(2,n-k-2,N)*(n-k-1);
    40             ans %= N;
    41             printf("%I64d
    ",ans);
    42         }
    43 
    44     }
    45     return 0;
    46 }
    View Code
  • 相关阅读:
    TP框架基础
    PHP文件上传
    layui-简单的登录注册界面
    layui-注册界面
    JavaScript原生Ajax请求纯文本数据
    ajax异步请求数据
    PHP数据库连接
    PHP页面跳转以及伪登录实例
    OVER 分析函数
    Ubuntu 16 vi输入方向键会变成ABCD的解决方法
  • 原文地址:https://www.cnblogs.com/0803yijia/p/3209446.html
Copyright © 2020-2023  润新知