2018焦作网络赛G-Give Candies

G: Give Candies

时间限制: 1 Sec  内存限制: 128 MB

题目描述

There are N children in kindergarten. Miss Li bought them N candies。To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1…N), and each time a child is invited, Miss Li randomly gives him some candies (at least one). The process goes on until there is no candy. Miss Li wants to know how many possible different distribution results are there.

输入

The first line contains an integer T, the number of test case.
The next T lines, each contains an integer N.
1 ≤ T ≤ 100
1 ≤ N ≤ 10^100000

输出

For each test case output the number of possible results (mod 1000000007).

样例输入

1
4

样例输出

8

分析ans=2^(n-1)

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int maxn=1e7+7;
 5 const ll mod=1e9+7;
 6 char arr[maxn];
 7 ll bit[15];
 8 ll qpow(ll a,ll b,ll c)
 9 {
10     if(b==0)return 1;
11     ll ans=1;
12     while(b)
13     {
14         if(b&1)ans=(ans*a)%mod;
15         a=a*a%mod;
16         b>>=1;
17     }
18     return ans%mod;
19 }
20 ll inv(ll a,ll m)
21 {
22     if(a==1)return 1;
23     return inv(m%a,m)*(m-m/a)%m;
24 }
25 int main()
26 {
27     int t;
28     scanf("%d",&t);
29     bit[0]=1;
30     ll inv2=inv(2,mod);
31     for(int i=1;i<10;i++)
32     {
33         bit[i]=bit[i-1]*2;
34     }
35     while(t--)
36     {
37         scanf("%s",arr);
38         int len=strlen(arr);
39         ll ans=1;
40         for(int i=0;i<len;i++)
41         {
42             ans=qpow(ans,10,mod)%mod;
43             ans=ans*bit[arr[i]-‘0‘]%mod;
44         }
45         ans*=inv2;
46         printf("%lld\n",(ans+mod)%mod);
47     }
48     return 0;
49 }

 

原文地址:https://www.cnblogs.com/CharlieWade/p/11293918.html

时间: 2024-10-03 15:48:30

2018焦作网络赛G-Give Candies的相关文章

[2018 ACM-ICPC 焦作赛区网络赛] G - Give Candies(找规律+快速幂)

题目链接 There are N children in kindergarten. Miss Li bought them N candies. To make the process more interesting, Miss Li comes up with the rule: All the children line up according to their student number (1...N)(1...N), and each time a child is invite

2018焦作网络赛 E Jiu Yuan Wants to Eat(线段树+树链剖分)

题意 对一个有1e5个点,点权初值为0的树上进行4种操作: 1.结点u到结点v上的所有点权乘x. 2.结点u到结点v上所有的点权加x. 3.结点u到结点v上所有的点权取非. 4.结点u到结点v路径上点权的和. 答案模\(2^{64}\) 思路 对操作1.2树链剖分加线段树维护即可,对操作3,取非操作为:一个二进制位上都为1 的数减去当前值,即:\(2^{64}-1-x\) , 由于答案模\(2^{64}\),通过点权用unsigned long long,只需维护\(-(x+1)\) 操作即可.

2018沈阳网络赛G

容斥+状压 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll MOD = 1e9+7; #include<vector> //const int MAX = 110; const int N = 100000; int arr[6000000];//p[N]用来存质数 ll n; int p; vector<ll>v; void getp(ll m, ll n) { /

2018焦作网络赛B

dp维护一下最大值与最小值,注意边界情况的判定. #include <iostream> #include <cstring> using namespace std; const long long inf = (long long)1e18+(long long)9; long long dp[7][1005]; long long dpx[7][1005]; int f[1005]; char s[15]; int main() { int T; // int l; int

2018焦作网络赛E

区间更新加法与乘法,x取反是2^64-x-1,由于取模所以取反变成-x-1,就区间+1再*-1就可以了,最后区间询问求和. 待补 原文地址:https://www.cnblogs.com/LMissher/p/9655105.html

2018焦作网络赛 - Poor God Water 一道水题的教训

本题算是签到题,但由于赛中花费了过多的时间去滴吧格,造成了不必要的浪费以及智商掉线,所以有必要记录一下 题意:方格从1到n,每一格mjl可以选择吃鱼/巧克力/鸡腿,求走到n格时满足 1.每三格不可重复同一种食物 2.每三格均不同食物时中间格子不可吃巧克力 3.每三格前后两格不可同时吃巧克力 以上三个条件的方案数,n<1e10 太长不看版:打表+快速幂AC 长篇吐槽版 很显然的,设\(dp[n][i][j][k]\),走到第\(n\)格时第\(n-2\)格的食物是\(i\),第\(n-1\)的食物

2018焦作网络赛J

不知道题意,队友用java大数+二分过了? import java.util.Arrays; import java.util.Scanner; import java.io.*; import java.math.*; public class Main { static boolean check(BigInteger num,BigInteger n) { boolean flag = true; BigInteger a = new BigInteger("0"); BigIn

[ACM-ICPC 2018 沈阳网络赛] G. Spare Tire (思维+容斥)

A sequence of integer \lbrace a_n \rbrace{an?} can be expressed as: \displaystyle a_n = \left\{ \begin{array}{lr} 0, & n=0\\ 2, & n=1\\ \frac{3a_{n-1}-a_{n-2}}{2}+n+1, & n>1 \end{array} \right.an?=????0,2,23an−1?−an−2??+n+1,?n=0n=1n>1? N

2018焦作网络赛-E- Jiu Yuan Wants to Eat

题目描述 You ye Jiu yuan is the daughter of the Great GOD Emancipator.  And when she becomes an adult, she will be queen of Tusikur, so she wanted to travel the world while she was still young. In a country, she found a small pub called Whitehouse. Just