焦作网络赛

B .

A prince of the Science Continent was imprisoned in a castle because of his contempt for mathematics when he was young, and was entangled in some mathematical curses. He studied hard until he reached adulthood and decided to use his knowledge to escape the castle.

There are NNN rooms from the place where he was imprisoned to the exit of the castle. In the ithi^{th}ith room, there is a wizard who has a resentment value of a[i]a[i]a[i]. The prince has MMM curses, the jthj^{th}jth curse is f[j]f[j]f[j], and f[j]f[j]f[j] represents one of the four arithmetic operations, namely addition('+'), subtraction('-'), multiplication('*'), and integer division('/'). The prince's initial resentment value is KKK. Entering a room and fighting with the wizard will eliminate a curse, but the prince's resentment value will become the result of the arithmetic operation f[j]f[j]f[j] with the wizard's resentment value. That is, if the prince eliminates the jthj^{th}jth curse in the ithi^{th}ith room, then his resentment value will change from xxx to (x f[j] a[i]x f[j] a[i]x f[j] a[i]), for example, when x=1,a[i]=2,f[j]=x=1, a[i]=2, f[j]=x=1,a[i]=2,f[j]='+', then xxx will become 1+2=31+2=31+2=3.

Before the prince escapes from the castle, he must eliminate all the curses. He must go from a[1]a[1]a[1] to a[N]a[N]a[N] in order and cannot turn back. He must also eliminate the f[1]f[1]f[1] to f[M]f[M]f[M] curses in order(It is guaranteed that N≥MNge MNM). What is the maximum resentment value that the prince may have when he leaves the castle?

Input

The first line contains an integer T(1≤T≤1000)T(1 le T le 1000)T(1T1000), which is the number of test cases.

For each test case, the first line contains three non-zero integers: N(1≤N≤1000),M(1≤M≤5)N(1 le N le 1000), M(1 le M le 5)N(1N1000),M(1M5) and K(−1000≤K≤1000K(-1000 le K le 1000K(1000K1000), the second line contains NNN non-zero integers: a[1],a[2],...,a[N](−1000≤a[i]≤1000)a[1], a[2], ..., a[N](-1000 le a[i] le 1000)a[1],a[2],...,a[N](1000a[i]1000), and the third line contains MMM characters: f[1],f[2],...,f[M](f[j]=f[1], f[2], ..., f[M](f[j] =f[1],f[2],...,f[M](f[j]='+','-','*','/', with no spaces in between.

Output

For each test case, output one line containing a single integer.

样例输入

3
2 1 5
2 3
/
3 2 1
1 2 3
++
4 4 5
1 2 3 4
+-*/

样例输出

2
6
3
题意 : 给你 n 个房间, m 种可以操作的字符,问你最大的得分是多少,初始的时候有一个初始分数
思路分析 : dp[i][j] 定义到达第 i 个房间使用 j 个字符的最大得分是多,但是这个题设计 乘法和除法 且每个房间的数字有正有负,因此只维护一个最大值是不太可行的,所以我们同时再维护一下最小值即可
代码示例:
#define ll long long
const ll maxn = 1e3+5;
const ll inf = 0x3f3f3f3f;

ll n, m, k;
ll arr[maxn];
char s[10];
ll dpmax[maxn][10], dpmin[maxn][10];

ll fun(ll x, char ch, ll y){
    if (ch == '+') return x+y;
    if (ch == '-') return x-y;
    if (ch == '*') return x*y;
    if (ch == '/') return x/y;
}

int main() {
    ll t;
    
    cin >> t;
    while(t--){
        scanf("%lld%lld%lld", &n, &m, &k);
        for(ll i = 1; i <= n; i++) scanf("%lld", &arr[i]);
        scanf("%s", s+1);
        
        memset(dpmax, 0x8f, sizeof(dpmax));
        memset(dpmin, inf, sizeof(dpmin));
        dpmax[0][0] = dpmin[0][0] = k;
        for(ll i = 1; i <= n; i++){
            dpmax[i][0] = dpmin[i][0] = k;
            for(ll j = 1; j <= min(i, m); j++){
                dpmax[i][j] = max(dpmax[i-1][j], max(fun(dpmax[i-1][j-1], s[j], arr[i]), fun(dpmin[i-1][j-1], s[j], arr[i])));
                dpmin[i][j] = min(dpmin[i-1][j], min(fun(dpmax[i-1][j-1], s[j], arr[i]), fun(dpmin[i-1][j-1], s[j], arr[i])));
            }
        }
        printf("%lld
", dpmax[n][m]);
    }
    return 0;
}

There are NNN children in kindergarten. Miss Li bought them NNN 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)(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.

Input

The first line contains an integer TTT, the number of test case.

The next TTT lines, each contains an integer NNN.

1≤T≤1001 le T le 1001T100

1≤N≤101000001 le N le 10^{100000}1N10100000

Output

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

样例输入

1
4

样例输出

8

思路分析 : 发现这题其实就是让求 2^(n-1) 的值是多少不过数特别大,欧拉降幂可以

代码示例:

#define ll long long
const ll maxn = 1e5+5;
const ll mod = 1e9+7;

char s[maxn];
ll qw(ll a, ll b){
    ll res = 1;
    while(b){
        if (b&1) res = res*a%mod;
        a = a*a%mod;
        b >>= 1;
    }
    return res;
}
int main() { 
    ll t;
    ll n;
    
    cin >> t;
    while(t--){
        scanf("%s", s+1);
        ll len = strlen(s+1);
        ll num = 0;
        ll phi = mod-1;
        for(ll i = 1; i <= len; i++){
            num = num*10 + (s[i]-'0');
            num %= phi;
        }
        num = (num-1+phi)%phi;
        //printf("num = %lld
", num);
        printf("%lld
", qw(2, num+phi));
    }
    return 0;
}

J .

Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don't know which one to choose, so they use a way to make decisions.

They have several boxes of candies, and there are ii candies in the i^{th}ith box, each candy is wrapped in a piece of candy paper. Jessie opens the candy boxes in turn from the first box. Every time a box is opened, Jessie will take out all the candies inside, finish it, and hand all the candy papers to Justin.

When Jessie takes out the candies in the N^{th}Nth box and hasn't eaten yet, if the amount of candies in Jessie's hand and the amount of candy papers in Justin's hand are both perfect square numbers, they will choose Arena of Valor. If only the amount of candies in Jessie's hand is a perfect square number, they will choose Hearth Stone. If only the amount of candy papers in Justin's hand is a perfect square number, they will choose Clash Royale. Otherwise they will choose League of Legends.

Now tell you the value of NN, please judge which game they will choose.

Input

The first line contains an integer T(1 le T le 800)T(1T800) , which is the number of test cases.

Each test case contains one line with a single integer: N(1 le N le 10^{200})N(1N10200) .

Output

For each test case, output one line containing the answer.

样例输入

4
1
2
3
4

样例输出

Arena of Valor
Clash Royale
League of Legends
Hearth Stone

题意 : 问你 n 是否是一个可开根数, 1-n-1求和是否是一个可开根数,判断输出即可

思路分析 : 套的JAVA牛顿迭代的板子

代码示例:

import java.math.BigInteger;
import java.math.*;
import java.math.BigInteger;
import java.util.Scanner;


import java.util.*; 
public class Main
{
    public static BigInteger bigSqrt(String s){
         Scanner cin=new Scanner(System.in);
          BigInteger remain=BigInteger.ZERO;
          BigInteger odd=BigInteger.ZERO;
          BigInteger ans=BigInteger.ZERO;
          int group=0,k=0;
          if(s.length()%2==1)
          {
                  group=s.charAt(0)-'0';
                  k=-1;
          }
          else
          {
                  group=(s.charAt(0)-'0')*10+s.charAt(1)-'0';
                  k=0;
          }
          for(int j=0;j<(s.length()+1)/2;j++)
          {
                  if(j!=0)
                  group=(s.charAt(j*2+k)-'0')*10+s.charAt(j*2+k+1)-'0';
                  odd=BigInteger.valueOf(20).multiply(ans).add(BigInteger.ONE);
                  remain=BigInteger.valueOf(100).multiply(remain).add(BigInteger.valueOf(group));
                  int count=0;
                  while(remain.compareTo(odd)>=0)
                  {
                         count++;
                         remain=remain.subtract(odd);
                         odd=odd.add(BigInteger.valueOf(2));
                  }
                  ans=ans.multiply(BigInteger.TEN).add(BigInteger.valueOf(count));
          }
//          System.out.println(ans);
          
//        cin.close();
        return ans;
    }
       public static void main(String[] args) 
       {
    	   Scanner cin = new Scanner(System.in);
           int t;
   		   t = cin.nextInt();
   		   String s;
   		   BigInteger n;
   		   
   		   for(int i = 1; i <= t; i++) {
   			   n = cin.nextBigInteger() ;
   			   s = n.toString();
   			   BigInteger x = bigSqrt(s);
   			   BigInteger c1 = x.pow(2);
   			   int flag1 =  0;
   			   if (n.compareTo(c1) == 0) flag1 = 1;
   			   
   			   BigInteger m = n.subtract(BigInteger.ONE);
   			   BigInteger sum = n.multiply(m);
   			   BigInteger m2 = BigInteger.valueOf(2);
   			   sum = sum.divide(m2);
   			   s = sum.toString();
   			   x = bigSqrt(s) ;
   			   BigInteger c2 = x.pow(2);
   			   int flag2 =  0;
   			   if (sum.compareTo(c2) == 0) flag2 = 1;
   			   
   			if ((flag1 == 1) && (flag2 == 1)) System.out.println("Arena of Valor");
	        else if ((flag1 == 1) && (flag2 == 0)) System.out.println("Hearth Stone");
	        else if ((flag1 == 0) && (flag2 == 1)) System.out.println("Clash Royale");
	        else System.out.println("League of Legends");
   			   
   		   }

              cin.close();
      }
}

K .

There are NNN different kinds of transport ships on the port. The ithi^{th}ith kind of ship can carry the weight of V[i]V[i]V[i] and the number of the ithi^{th}ith kind of ship is 2C[i]−12^{C[i]} - 12C[i]1. How many different schemes there are if you want to use these ships to transport cargo with a total weight of SSS?

It is required that each ship must be full-filled. Two schemes are considered to be the same if they use the same kinds of ships and the same number for each kind.

Input

The first line contains an integer T(1≤T≤20)T(1 le T le 20)T(1T20), which is the number of test cases.

For each test case:

The first line contains two integers: N(1≤N≤20),Q(1≤Q≤10000)N(1 le N le 20), Q(1 le Q le 10000)N(1N20),Q(1Q10000), representing the number of kinds of ships and the number of queries.

For the next NNN lines, each line contains two integers: V[i](1≤V[i]≤20),C[i](1≤C[i]≤20)V[i](1 le V[i] le 20), C[i](1 le C[i] le 20)V[i](1V[i]20),C[i](1C[i]20), representing the weight the ithi^{th}ith kind of ship can carry, and the number of the ithi^{th}ith kind of ship is 2C[i]−12^{C[i]} - 12C[i]1.

For the next QQQ lines, each line contains a single integer: S(1≤S≤10000)S(1 le S le 10000)S(1S10000), representing the queried weight.

Output

For each query, output one line containing a single integer which represents the number of schemes for arranging ships. Since the answer may be very large, output the answer modulo 100000000710000000071000000007.

样例输入

1
1 2
2 1
1
2

样例输出

0
1

题意 :给你 n 种船,同时再给你 n 种船的价值以及他的数量是 2^c-1, 询问你你当价值敲好是S的时候的方案数
思路分析 : 定义 dp[i] 表示价值为 i 的方案数,再用一下多重背包的二进制优化即可
代码示例:
#define ll long long
const ll maxn = 1e4+5;
const ll mod = 1e9+7;

ll n, q, v;
ll a[25][2];
ll dp[maxn];

void solve(){
    memset(dp, 0, sizeof(dp));
    dp[0] = 1;
    for(ll i = 1; i <= n; i++){
        ll k = 1, ncount = pow(2, a[i][1])-1;
        while(k <= ncount){
            ll val = k*a[i][0];
            for(ll j = 10000; j >= val; j--){
                dp[j] += dp[j-val];
                dp[j] %= mod;
            }
            ncount -= k;
            k <<= 1;
        } 
    }
}

int main() {
    ll t;
    
    cin >> t;
    while(t--){
        scanf("%lld%lld", &n, &q);
        for(ll i = 1; i <= n; i++){
            scanf("%lld%lld", &a[i][0], &a[i][1]);            
        }
        solve();
        while(q--){
            scanf("%lld", &v);
            printf("%lld
", dp[v]);
        }
    }
    return 0;
}

L .

God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous.

Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 333 continuous hours when he eats only one kind of food, he will be unhappy. Besides, if there are 333 continuous hours when he eats all kinds of those, with chocolate at the middle hour, it will be dangerous. Moreover, if there are 333 continuous hours when he eats meat or fish at the middle hour, with chocolate at other two hours, it will also be dangerous.

Now, you are the doctor. Can you find out how many different kinds of diet that can make God Water happy and safe during NNN hours? Two kinds of diet are considered the same if they share the same kind of food at the same hour. The answer may be very large, so you only need to give out the answer module 100000000710000000071000000007.

Input

The fist line puts an integer TTT that shows the number of test cases. (T≤1000T le 1000T1000)

Each of the next TTT lines contains an integer NNN that shows the number of hours. (1≤N≤10101 le N le 10^{10}1N1010)

Output

For each test case, output a single line containing the answer.

样例输入

3
3
4
15

样例输出

20
46
435170
题意 : 有 3 种饮食,告诉你一些连续3天饮食搭配不健康的情况,问N天后饮食健康的方案有多少种?
思路分析 : 首先若只有两天的话,则有 9种情况,均符合要求,第三天再添加的时候纸上推一下,发现其实就是个 9*9的矩阵,一个矩阵快速幂即可
代码示例:

#define ll long long
const ll maxn = 1e6+5;
const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const ll inf = 0x3f3f3f3f;

char s[1000];
struct mat
{
    ll a[15][15];
};
const ll modulu[15][15] = {
    {0, 0, 0, 1, 0, 0, 1, 0, 0},
    {1, 0, 0, 1, 0, 0, 1, 0, 0},
    {1, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 1, 0, 0, 1, 0, 0, 1, 0},
    {0, 1, 0, 0, 0, 0, 0, 1, 0},
    {0, 1, 0, 0, 1, 0, 0, 0, 0},
    {0, 0, 1, 0, 0, 0, 0, 0, 1},
    {0, 0, 0, 0, 0, 1, 0, 0, 1},
    {0, 0, 1, 0, 0, 1, 0, 0, 0}
};
ll n;
mat mul(mat a, mat b){
    mat r;
    memset(r.a, 0, sizeof(r.a));
     
    for(ll i = 0; i < 9; i++){
        for(ll j = 0; j < 9; j++){
            for(ll k = 0; k < 9; k++){
                r.a[i][j] += (a.a[i][k]*b.a[k][j])%mod;
                r.a[i][j] %= mod;           
            }
        }
    }
    return r;
}
 
mat qpow(mat a, ll x){
    mat b;
    memset(b.a, 0, sizeof(b.a));
    for(ll i = 0; i < 9; i++) b.a[i][i] = 1;
     
    while(x){
        if (x&1) b = mul(b, a);
        a = mul(a, a);
        x >>= 1;
    }
    return b;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ll t;
    
    cin >> t;
    while(t--){
        cin >> n;
        mat a;
        memcpy(a.a, modulu, sizeof(modulu));
        if (n == 1) {printf("3
"); continue;}
        else if (n == 2) {printf("9
"); continue;}
        
        a = qpow(a, n-2);
        ll sum = 0;
        for(ll i = 0; i < 9; i++){
            for(ll j = 0; j < 9; j++){
                sum = (sum+a.a[i][j])%mod;
            }
        }
        printf("%lld
", sum);
    }
    return 0;
}
东北日出西边雨 道是无情却有情
原文地址:https://www.cnblogs.com/ccut-ry/p/9652595.html