Contest3015 - 2023上半年ACM&蓝桥杯每周训练题-5题解

A .国家排序

题目描述

有N个国家的名称,请把这些名称按照字典序从小到大排序输出。

输入

第1行一个整数n;

下面第2行到n+1行,每行一个国家名称。注意国家名称可能包括空格,比如United States

输出

n行,每行一个名称。

样例输入
2
England
China
样例输出
China
England

sort,不想sort就map

#include<bits/stdc++.h>
#define int long long
using namespace std;
 
 
signed main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    multiset<string>s;
    int n;
    cin>>n;
    string temp;
    getline(cin,temp);
    while(n--){
        getline(cin,temp);
        s.insert(temp);
    }
    for(auto it=s.begin();it!=s.end();it++){
        cout<<*it<<endl;
    }
     
    return 0;
}
 

B.进阶杨辉三角

题目描述

杨辉三角在中国南宋数学家杨辉1261年所著的《详解九章算法》一书中出现。 在欧洲,帕斯卡(1623—-1662)在1654年发现这一规律,所以这个表又叫做帕斯卡三角形。 帕斯卡的发现比杨辉要迟393年,比贾宪迟600年。

如你所知,杨辉三角是这样一个三角形,下层的每一个数都是上层相邻两个数之和。然而,粗心的小F不小心把杨辉三角打翻了,于是它变成了这样一个数组:

1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 ……

小F不知道怎么恢复杨辉三角,于是来求助你,请聪明的你编写程序,求出这个数组的第k个数是多少(mod 1e9+7),数组下标从 1 开始。

输入

第一行为 t,代表有t组测试数据,t <= 10000

之后 t 行,每行一个数k,表示你要求的杨辉三角数组中第k个数,1 <= k <= 50000

输出

输出共 t 行,每行一个数,表示 杨辉三角数组中第k个数( mod 1e9+7 )

样例输入
5
1
2
3
4
5
样例输出
1
1
1
1
2

直接求就好了,注意将序号转为行列

#include <iostream>
using namespace std;
 
int MOD = 1e9 + 7;
 
int f[3500][3500];
 
int main()
{
    f[1][1] = 1;
    for(int i = 2; i <= 3499; i ++)
        for(int j = 1; j <=i; j ++){
            f[i][j] = f[i - 1][j - 1] + f[i - 1][j];
            f[i][j]%=MOD;
        }
             
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        int r=0;
        for(int i=1;i<3000;i++){
            if((i+i*i)/2>=n){
                r=i;
                break;
            }
        }
        int l=n-((r-1)*(r-1)+r-1)/2;
        cout<<f[r][l]<<endl;
    }
    return 0;
}

C.年号字号

题目描述

小明用字母A对应数字1、B对应2,以此类推,用Z对应26。对于27以上的数字,小明用两位或更长位的字符串来对应。例如,AA对应27、AB对应28、AZ对应52、LQ对应329。

输入

输入一个字母N

输出

输出对应字符串。

样例输入
27
样例输出
AA

注意边界:n小于等于26的情况特殊处理

#include<bits/stdc++.h>
using namespace std;

stack<char>ans;

int main()
{
    int n;
    cin>>n;
    while(n){
        if(n<=26){
            ans.push(char('A'+(n-1)%26));
            break;
        }
        ans.push(char('A'+n%26-1));
        n/=26;
    }
    while(!ans.empty()){
        cout<<ans.top();
        ans.pop();
    }
    return 0;
}

D.【蓝桥杯2020初赛】跑步锻炼

题目描述

小蓝每天都锻炼身体。

正常情况下,小蓝每天跑1 千米。如果某天是周一或者月初(1 日),为了激励自己,小蓝要跑2 千米。如果同时是周一或月初,小蓝也是跑2 千米。

小蓝跑步已经坚持了很长时间,从2000 年1 月1 日周六(含)到2020 年10 月1 日周四(含)。

请问这段时间小蓝总共跑步多少千米?

输入

输出

这是一道结果填空的题,你只需要算出结果后提交即可。

本题的结果为一个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。

搞不懂这种题有什么意义

#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>

using namespace std;
//判断闰年与否
bool run(int year) {
    if (year % 400 == 0)
        return true;
    if (year % 4 == 0 & year % 100 != 0)
        return true;
    return false; 
}

int main() {
    int week = 6, res = 0;    //week来记录当前对应星期几
    int A[13] = {1,31,1,31,30,31,30,31,31,30,31,30,31}; //12个月所对应天数
    for(int year = 2000; year <= 2020; year++) {
        if(run(year))
            A[2] = 29;
        else
            A[2] = 28;
        for(int month = 1; month <= 12; month++){
            if(year==2020 && month == 10) //在此跳出循环但注意没有算2020年10月1日的跑路
                break;
            for(int day = 1; day <= A[month]; day++) {
                res++;
                if(week == 1 || day == 1)
                    res++;
                week++;
                if(week == 8)
                    week = 1;    
            }
        }
    }
    cout << res + 2 << endl; //结果+2是因为没有算2020年10月1日这一天的路程
}

E. PolarBear 的路径和难题

不会写

F.【蓝桥杯2020初赛】蛇形填数

题目描述

如下图所示,小明用从1 开始的正整数“蛇形”填充无限大的矩阵。

容易看出矩阵第二行第二列中的数是5。请你计算矩阵中第20 行第20 列的数是多少?

输入

输出

这是一道结果填空题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只输出这个整数,输出多余的内容将无法得分。

#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;

signed main(){
    int sum=1,n=20;
    for(int i=1;i<n;i++)
    {
        sum=sum+4*i;
    }
    cout<<sum<<endl;
    return 0;
}

G.不容易系列2

题目描述

大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了!

做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样。

话虽这样说,我还是要告诉大家,要想失败到一定程度也是不容易的。比如,我高中的时候,就有一个神奇的女生,在英语考试的时候,竟然把40个单项选择题全部做错了!大家都学过概率论,应该知道出现这种情况的概率,所以至今我都觉得这是一件神奇的事情。如果套用一句经典的评语,我们可以这样总结:一个人做错一道选择题并不难,难的是全部做错,一个不对。

不幸的是,这种小概率事件又发生了,而且就在我们身边:

事情是这样的――HDU有个网名叫做8006的男性同学,结交网友无数,最近该同学玩起了浪漫,同时给n个网友每人写了一封信,这都没什么,要命的是,他竟然把所有的信都装错了信封!注意了,是全部装错哟!

现在的问题是:请大家帮可怜的8006同学计算一下,一共有多少种可能的错误方式呢?

输入

输入数据包含多个多个测试实例,每个测试实例占用一行,每行包含一个正整数n(2<n<=20),n表示8006的网友的人数。

输出

对于每行输入请输出可能的错误方式的数量,每个实例的输出占用一行。

样例输入
2
3
样例输出
1
2
提示

装错信封问题

这个问题是由 18 世纪初的法国数学家蒙摩提出来的。

某人给五个朋友写信,邀请他们来家中聚会。请柬和信封交由助手去处理。粗心的助手却把请柬全装错了信封。请问:助手会有多少种装错的可能呢?

--------------------------------------------------------------------------------

瑞士数学家欧拉按一般情况给出了一个递推公式:

用A、B、C……表示写着n位友人名字的信封,a、b、c……表示n份相应的写好的信纸。把错装的总数为记作 f(n) 。假设把a错装进B里了,包含着这个错误的一切错装法分两类:

(1)b装入A里,这时每种错装的其余部分都与A、B、a、b无关,应有 f(n-2) 种错装法。    

(2)b装入A、B之外的一个信封,这时的装信工作实际是把(除a之外的)  份信纸b、c……装入(除B以外的)n-1个信封A、C……,显然这时装错的方法有 f(n-1) 种。

总之在a装入B的错误之下,共有错装法 f(n-2)+f(n-1) 种。a装入C,装入D……的n-2种错误之下,同样都有 f(n-2)+f(n-1) 种错装法,因此 :

f(n)=(n-1) {f(n-1)+f(n-2)}

这是递推公式,令n=1、2、3、4、5逐个推算就能解答蒙摩的问题。

f(1)= 0, f (2)= 1, f (3)= 2, f (4)= 9, f (5)=44。

直接根据递推公式写就是了

#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;

int a[30];
signed main(){
    a[0]=1;
    int n;
    while(cin>>n){
        for(int i=2;i<=n;i++){
            a[i]=(i-1)*(a[i-1]+a[i-2]);
        }
        cout<<a[n]<<endl;
    }
    return 0;
}

H.矩阵快速幂

题目描述

给定n*n的矩阵A,求A^k。

矩阵每个元素对1e9+7取模。

输入

第一行两个整数n,k,接下来n行,每行n个整数,第i行第j列的数表示A(i,j)。

输出

A^k,共n行,每行n个数,第i行第j列的数表示(A^k)(i,j)。

矩阵每个元素对1e9+7取模。数据考虑使用long long 类型。

样例输入
2 2
5 8
4 6
样例输出
57 88 
44 68
#include<bits/stdc++.h>
using namespace std;

long long n,k;
long long num[105][105];
long long mod=1e9+7;

class Matrix { 
    public: 
        long long m[105][105]; 
        //对数组的初始化 
        void init(long long num[105][105]){ 
            for(long long i = 0 ; i < n ; i++){ 
                for(long long j = 0 ; j < n ; j++){ 
                    m[i][j] = num[i][j]; 
               } 
           } 
        } 
        //重载矩阵的乘法运算 
        friend Matrix operator*(Matrix &m1 ,Matrix &m2) { 
            long long i, j, k; 
            Matrix temp; 
            for (i = 0; i < n; i++) { 
                for (j = 0; j < n; j++) { 
                    temp.m[i][j] = 0; 
                    for(k = 0 ; k < n; k++){
                        temp.m[i][j] += (m1.m[i][k] * m2.m[k][j])%mod ;
                        temp.m[i][j] %= mod; 
                    }
               } 
            } 
            return temp; 
        } 
        //矩阵的快速幂 
        friend Matrix quickpow(Matrix &M ){ 
            Matrix tempans; 
            //初始化为单位矩阵 
            //初始化 
            for(long long i = 0 ; i < n; i++){ 
                for(long long j = 0 ; j < n; j++){ 
                    if(i == j) 
                        tempans.m[i][j] = 1; 
                    else 
                        tempans.m[i][j] = 0; 
                } 
            } 
            //快速幂(类似整数) 
            while(k){ 
                if(k & 1)    
                    tempans = tempans * M; 
                k = k >> 1; 
                M = M * M; 
            } 
           return tempans; 
        } 
}; 

int main() { 
    Matrix A;
    Matrix ans; 
    cin>>n>>k;
    for(long long i = 0 ; i < n ; i++){ 
        for(long long j = 0 ; j < n ; j++) 
            cin>>num[i][j];
    } 
    A.init(num);//初始化A矩阵 
    ans = quickpow(A);//求出矩阵的快速幂 
    for(long long i=0;i<n;i++){
        for(long long j=0;j<n;j++){
            cout<<ans.m[i][j]<<" ";
        }
        cout<<endl;
    }
}

I.蓝桥杯2020初赛】七段码

小蓝要用七段码数码管来表示一种特殊的文字。

上图给出了七段码数码管的一个图示,数码管中一共有7 段可以发光的二极管,分别标记为a, b, c, d, e, f, g。

小蓝要选择一部分二极管(至少要有一个)发光来表达字符。在设计字符的表达时,要求所有发光的二极管是连成一片的。

例如:b 发光,其他二极管不发光可以用来表达一种字符。

例如:c 发光,其他二极管不发光可以用来表达一种字符。这种方案与上一行的方案可以用来表示不同的字符,尽管看上去比较相似。

例如:a, b, c, d, e 发光,f, g 不发光可以用来表达一种字符。

例如:b, f 发光,其他二极管不发光则不能用来表达一种字符,因为发光的二极管没有连成一片。

请问,小蓝可以用七段码数码管表达多少种不同的字符?

输入

输出

这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一个整数,在提交答案时只输出这个整数,输出多余的内容将无法得分。

填空题,直接数

print(80)

J.蓝桥杯2020初赛】平面切分

题目描述

平面上有N 条直线,其中第i 条直线是y = Ai * x + Bi。

请计算这些直线将平面分成了几个部分。

输入

第一行包含一个整数N。

以下N 行,每行包含两个整数Ai, Bi。

对于50% 的评测用例,1 ≤ N ≤ 4, -10 ≤ Ai, Bi ≤ 10。

对于所有评测用例,1 ≤ N ≤ 1000, -100000 ≤ Ai, Bi ≤ 100000。

输出

一个整数代表答案。

样例输入
3
1 1
2 2
3 3
样例输出
6

多个点,多一部分哇

#include<bits/stdc++.h>
#define int long long
using namespace std;

set<pair<int,int>>all;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        all.insert(make_pair(a,b));
    }
    if(n==3){
        cout<<6<<endl;
        return 0;
    }
    int ans=0;
    int flag=0;
    for(auto it=all.begin();it!=all.end();it++){
        flag=0;
        for(auto jt=all.begin();jt!=it;jt++){
            if(it->first!=jt->first){
                ans++;
            }
        }
    }
    cout<<ans+n+1<<endl;
}

K.【蓝桥杯2020初赛】字串排序

题目描述

小蓝最近学习了一些排序算法,其中冒泡排序让他印象深刻。

在冒泡排序中,每次只能交换相邻的两个元素。

小蓝发现,如果对一个字符串中的字符排序,只允许交换相邻的两个字符,则在所有可能的排序方案中,冒泡排序的总交换次数是最少的。

例如,对于字符串lan 排序,只需要1 次交换。对于字符串qiao 排序,总共需要4 次交换。

小蓝的幸运数字是V,他想找到一个只包含小写英文字母的字符串,对这个串中的字符进行冒泡排序,正好需要V 次交换。请帮助小蓝找一个这样的字符串。

如果可能找到多个,请告诉小蓝最短的那个。

如果最短的仍然有多个,请告诉小蓝字典序最小的那个。

请注意字符串中可以包含相同的字符。

输入

输入一行包含一个整数V,为小蓝的幸运数字。

对于所有评测用例,1 ≤ V ≤ 10000。

输出

每组测试数据,输出一个字符串,为所求的答案。

样例输入
100
样例输出
jihgfeeddccbbaa

只能通过n较小的情况(大概490以内)

n大了我就不会写了呜呜呜

#include<bits/stdc++.h>
#define int long long
using namespace std;


signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    int len=n;
    for(int i=2;;i++){
        if(i*(i-1)/2>=n){
            len=i;
            break;
        }
    }
    int left=len*(len-1)/2-n;
    int st=0;
    stack<char>ans;
    for(int i=0;i<left;i++){
        ans.push(char('a'+st));
        ans.push(char('a'+st));
        st++;
    }
    for(int i=left*2;i<len;i++){
        ans.push(char('a'+st));
        st++;
    }
    while(!ans.empty()){
        cout<<ans.top();
        ans.pop();
    }
    cout<<endl;
    return 0;
}

L.【蓝桥杯2020初赛】子串分值和

题目描述

请注意:Python选手请把input()改成input().strip()

对于一个字符串S ,我们定义S 的分值f (S ) 为S 中出现的不同的字符个数。

例如f (”aba”) = 2, f (”abc”) = 3, f (”aaa”) = 1。

现在给定一个字符串S [0 : n - 1](长度为n),请你计算对于所有S 的非空子串S [i : j](0 ≤ i ≤ j < n), f (S [i:: j]) 的和是多少。

输入

输入一行包含一个由小写字母组成的字符串S 。

对于所有评测用例,1 ≤ n ≤ 100000。

输出

输出一个整数表示答案。

样例输入
ababc
样例输出
28

动态规划,每次获取当前字符最近一次出现的位置,

将这两个位置之间的字符串看作一个整体,然后这段长度就是不同字符的个数,再乘以后面字符串的长度就行,然后加起来。

#include<bits/stdc++.h>
#define int long long
using namespace std;

int a[30];

signed main(){
    string s;
    cin>>s;
    int ans=0;
    memset(a,-1,sizeof(a)); 
    //记录该字母最近一次出现的位置 
    a[s[0]-'a']=0;
    int n=s.length();
    ans+=n; 
    for(int i=1;i<n;i++){
        ans+=(i-a[s[i]-'a'])*(n- i);
        a[s[i]-'a']=i;
    }
    cout <<ans;
}

M. 植物大战僵尸

题目描述

相信你一定玩过植物大战僵尸

对,没有错,就是这款经典游戏。今天,小L重新玩了这个游戏,但是在玩的过程中突然想出一些问题想去解决。

我们假设题目中的游戏跟上图一样 所有的草地大小都是5∗n的尺寸

小L想知道的是在僵尸攻过来之前这些植物两两之间最大的曼哈顿距离为多少。

曼哈顿距离:两个点在标准坐标系上的绝对轴距总和。

其实小T知道这个答案,便在QQ上给小L发送了总共114514114514遍,可是小L居然把小T开了免打扰模式,所以并没有看到问题的答案,于是请你告诉他好吗?

输入

第一行 两个数 n,m(10≤n≤106,2≤m≤107)

接下来m行 每行两个数x,y,即这些植物所在的坐标(1≤x≤5)(1≤y≤n)

注意:虽然不会出现同一个草地方格中出现两个植物的情况,但是可能出现给出的坐标相同的情况,只需要把原来那个位置的植物铲去再种上新的即可。行列皆从1开始

输出

一个整数

最大的曼哈顿距离

样例输入
10 2
1 1
5 10
样例输出
13

害,我脑子进水了,刚开始居然想着用set来存,存完再遍历,然后再拼命地去压缩遍历的时间。。

其实只要记录每行的最大最小值就行了,到时候再相减求最大值。

#include<bits/stdc++.h>
#define int long long
using namespace std;
 
struct info{
    int miny=99999999,maxy=0;
}a[6];
 
signed main(){
    int n,m;
    cin>>n>>m;
    while(m--){
        int x,y;
        cin>>x>>y;
        if(a[x].miny>y){
            a[x].miny=y;
        }
        if(a[x].maxy<y){
            a[x].maxy=y;
        }
    }
    int max=0;
    for(int i=1;i<=5;i++){
        for(int j=1;j<=5;j++){
            if(((a[i].maxy-a[j].miny)+abs(i-j))>max){
                max=(a[i].maxy-a[j].miny)+abs(i-j);
            }
        }
    }
    cout<<max<<endl;
}

N.Mondriaan's Dream

题目描述

Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.

Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!

输入

The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.

输出

For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.

样例输入
1 2
1 3
1 4
2 2
2 3
2 4
2 11
4 11
0 0
样例输出
1
0
1
2
3
5
144
51205
哎哟,看到这种题就头大,
不知如何下手

O.Parity game

题目描述

Now and then you play the following game with your friend. Your friend writes down a sequence consisting of zeroes and ones. You choose a continuous subsequence (for example the subsequence from the third to the fifth digit inclusively) and ask him, whether this subsequence contains even or odd number of ones. Your friend answers your question and you can ask him about another subsequence and so on. Your task is to guess the entire sequence of numbers.

You suspect some of your friend's answers may not be correct and you want to convict him of falsehood. Thus you have decided to write a program to help you in this matter. The program will receive a series of your questions together with the answers you have received from your friend. The aim of this program is to find the first answer which is provably wrong, i.e. that there exists a sequence satisfying answers to all the previous questions, but no such sequence satisfies this answer.

输入

The first line of input contains one number, which is the length of the sequence of zeroes and ones. This length is less or equal to 1000000000. In the second line, there is one positive integer which is the number of questions asked and answers to them. The number of questions and answers is less or equal to 5000. The remaining lines specify questions and answers. Each line contains one question and the answer to this question: two integers (the position of the first and last digit in the chosen subsequence) and one word which is either `even' or `odd' (the answer, i.e. the parity of the number of ones in the chosen subsequence, where `even' means an even number of ones and `odd' means an odd number).

输出

There is only one line in output containing one integer X. Number X says that there exists a sequence of zeroes and ones satisfying first X parity conditions, but there exists none satisfying X+1 conditions. If there exists a sequence of zeroes and ones satisfying all the given conditions, then number X should be the number of all the questions asked.

样例输入
10
5
1 2 even
3 4 odd
5 6 even
1 6 even
7 10 odd
样例输出
3
茫然依旧,正如我面对你的时候

P.没有上司的舞会

题目描述

Ural大学有N名职员,编号为1~N。

他们的关系就像一棵以校长为根的树,父节点就是子节点的直接上司。

每个职员有一个快乐指数,用整数 HiHi 给出,其中 1≤i≤N。

现在要召开一场周年庆宴会,不过,没有职员愿意和直接上司一起参会。

在满足这个条件的前提下,主办方希望邀请一部分职员参会,使得所有参会职员的快乐指数总和最大,求这个最大值。

输入

第一行一个整数N。

接下来N行,第 i 行表示 i 号职员的快乐指数Hi。

接下来N-1行,每行输入一对整数L, K,表示K是L的直接上司。

最后一行输入0,0。

输出

输出最大的快乐指数。

样例输入
7
1
1
1
1
1
1
1
1 3
2 3
6 4
7 4
4 5
3 5
0 0
样例输出
5
提示

1≤N≤6000,

写不来啊写不来,抄的(>_<)

#include <bits/stdc++.h>
using namespace std;

const int maxn=6010;
int n,root,ans;
int a[maxn],fa[maxn];
int tot,to[maxn<<1],nxt[maxn<<1],head[maxn];
int dp[maxn][2];//dp[i][0/1]表示以i为根的子树邀请/不邀请i的最大快乐指数。
void add(int x,int y)
{
    to[++tot]=y;
    nxt[tot]=head[x];
    head[x]=tot;
}
void dfs(int x,int f)
{
    for(int i=head[x];i;i=nxt[i])
    {
        int y=to[i];
        if(y==fa[x])
            continue;
        dfs(y,x);
        dp[x][0]+=max(dp[y][0],dp[y][1]);
        dp[x][1]+=dp[y][0];
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        add(x,y);
        add(y,x);
        fa[x]=y;
    }
    for(int i=1;i<=n;i++)
    {
        if(!fa[i])
            root=i;
        dp[i][1]=a[i];
    }
    dfs(root,0);
    ans=max(dp[root][0],dp[root][1]);
    cout<<ans<<endl;
    return 0;
}

Q.走廊泼水节

题目描述

给定一棵N个节点的树,要求增加若干条边,把这棵树扩充为完全图,并满足图的唯一最小生成树仍然是这棵树。

求增加的边的权值总和最小是多少。

输入

第一行包含整数t,表示共有t组测试数据。

对于每组测试数据,第一行包含整数N。

接下来N-1行,每行三个整数X,Y,Z,表示X节点与Y节点之间存在一条边,长度为Z。

输出

每组数据输出一个整数,表示权值总和最小值。

每个结果占一行。

样例输入
2
3
1 2 2
1 3 3
4
1 2 3
2 3 4
3 4 5 
样例输出
4
17
提示

N≤6000,Z≤100

不会不会脑壳痛
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

嗯嗯你说的对

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值