首页 > 其他分享 >The 2022 ICPC Asia Hangzhou Regional Programming Contest

The 2022 ICPC Asia Hangzhou Regional Programming Contest

时间:2023-09-05 13:58:59浏览次数:47  
标签:tmp sz Contest int Regional Programming long charsize vec

The 2022 ICPC Asia Hangzhou Regional Programming Contest

No Bug No Game

 

 

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
typedef long long ll;

const int N = 3e3 + 10;

int f[N][N][2];

signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, k; cin >> n >> k;
    vector<vector<int>> vec(n + 1);
    int sum = 0;
    for(int i = 1; i <= n; i++){
        int sz; cin >> sz; sum += sz;
        vec[i].resize(sz + 1);
        for(int j = 1; j <= sz; j++){
            cin >> vec[i][j];
        }
    }
    memset(f, 128, sizeof(f));
    //前 i 个容量 j 是否装过一次部分物品
    f[0][0][0] = f[0][0][1] = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= k; j++){
            int sz = vec[i].size() - 1;
            //不选
            f[i][j][0] = f[i - 1][j][0];
            f[i][j][1] = f[i - 1][j][1];
            //完全选择
            if(j - sz >= 0){
                f[i][j][0] = max(f[i][j][0], f[i - 1][j - sz][0] + vec[i].back());
                f[i][j][1] = max(f[i][j][1], f[i - 1][j - sz][1] + vec[i].back());
            }
            //不完全选择
            for(int k = 1; k <= sz; k++){
                if(j - k >= 0)f[i][j][1] = max(f[i][j][1], f[i - 1][j - k][0] + vec[i][k]);
                else break;
            }
        }
    }
    if(sum > k)cout << max(f[n][k][0], f[n][k][1]) << endl;
    else cout << f[n][sum][0] << endl;
    return 0;
}
View Code

Master of Both

题意:给出n个字符串,m种字母顺序,对于每一种字母顺序,输出给出的字符串有多少逆序对。

思路:不论字母表怎么变,比较两个字符串的相应字母是不会变的,可以用字典树把所有字母对个数预处理出来,在字母表上求出对应的贡献即可

#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long
typedef long long ll;

const int N=1e6+5;
const int charsize=26;

int Trie[N][charsize];
bool isend[N];
int root,cnt,ans,res;
int calc[charsize][charsize], sum[N];

void insert(string s){
    int len=s.size();
    int now=0;
    for(int i=0;i<len;i++){
        int x=s[i]-'a';
        for(int j = 0; j < 26; j++){
            if(x == j) continue;
            calc[x][j] += sum[Trie[now][j]];
        }    
        if(!Trie[now][x])Trie[now][x]=++cnt;
        now=Trie[now][x];
        sum[now]++;
    }
    isend[now]=true;
    for(int i = 0; i < 26; i++) res += sum[Trie[now][i]];
}

signed main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, q; cin >> n >> q;
    for(int i = 1; i <= n; i++){
        string s; cin >> s;
        insert(s);
    }

    while(q--){
        string tmp; cin >> tmp;
        ans = 0;
        for(int i = 0; i < 26; i++){
            for(int j = i + 1; j < 26; j++){
                ans += calc[tmp[i] - 'a'][tmp[j] - 'a'];
            }
        }
        cout << ans + res << endl;
    }
    return 0;
}
View Code

 

标签:tmp,sz,Contest,int,Regional,Programming,long,charsize,vec
From: https://www.cnblogs.com/zhujio/p/17679362.html

相关文章

  • The 18th Heilongjiang Provincial Collegiate Programming Contest
    链接:https://codeforces.com/gym/104363A.MagicComputer#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;constexprintP=998244353;i64power(i64a,i64b){i64res=1;for(;b;b>>=1,a=a*a%P){......
  • The 10th Shandong Provincial Collegiate Programming Contest
    链接:https://codeforces.com/gym/104459A#include"bits/stdc++.h"usingnamespacestd;usingi64=longlong;stringS[]={"Monday","Tuesday","Wednesday","Thursday","Friday&q......
  • 【题解】AtCoder Beginner Contest 318(D - Ex)
    赛时过了A-G,Ex仿佛猜到了结论但是完全不懂多项式科技,就炸了。大家好像都秒了A,B,C就不写了。D.GeneralWeightedMaxMatching题目描述:给你一个加权无向完全图,图中有\(N\)个顶点,编号从\(1\)到\(N\)。连接顶点\(i\)和\(j\)的\((i<j)\)的权重为\(D_{i,j}\)。在......
  • AtCoder Beginner Contest 318
    A-FullMoonProblemStatementTakahashilikesfullmoons.Lettodaybeday\(1\).Thefirstdayonoraftertodayonwhichhecanseeafullmoonisday\(M\).Afterthat,hecanseeafullmoonevery\(P\)days,thatis,onday\(M+P\),day\(......
  • AtCoder Beginner Contest 201 E - Xor Distances
    E-XorDistances原题链接题意:设dist(i,j)即i到j之间路径的异或和,求树上所有两点之间dist(i,j)的和思路:dist(i,j)=dist(i,1)^dist(j,1)根据异或性质相同的部分会被消掉用bfs求得dist(i,1)优化两层i,j的枚举:通过遍历每个数的每一位1的个数cnt,以及0的个数n-cnt,从而在1^0=1......
  • AtCoder Beginner Contest 201 D - Game in Momotetsu World
    D-GameinMomotetsuWorld原题链接题意有一个H×W的方格,每个方格里写着'+'或'-'有一个初始在(1,1),(也就是左上角)的棋子,Takahashi和Aoki轮流向右或向下移动(Takahashi先手)。移动到写着'+'的方格上后,进行该步移动的玩家分数+1。否则该玩家分数−1,走到右下......
  • AtCoder Beginner Contest 317 D - President
    D-President原题链接题意:一共n轮,每一轮Xi>Yi(票数)时,X可以获得Zi张席位,反之亦然;最终席位总和多的就获胜;因此要使X获胜,求Y至少要给X多少个票思路:数据范围小,Z的和小于1e5可以用01背包的方法,前i轮中,X获得的席位不超过j的最小票数,再对X获胜情况中(X的席位>=m/2+1)取最小......
  • AtCoder Beginner Contest 317 C - Remembering the Days
    C-RememberingtheDays原题链接题意:每个点最多经过一次,求最长路思路:数据范围很小,深搜每个点能到其他点的所有路,取最大#include<bits/stdc++.h>usingnamespacestd;constintN=110;intg[N][N];intn,m;boolst[N];intw=0;intans=0;voiddfs(intu){ st[......
  • 【题解】Harbour.Space Scholarship Contest 2023-2024 D,E,F(CF1864)
    D.MatrixCascade题目描述:有一个大小为\(n\timesn\)的矩阵,由0和1组成。行的编号从上到下依次为\(1\)到\(n\),列的编号从左到右依次为\(1\)到\(n\)。第\(x\)行与第\(y\)列交叉处的单元格记为\((x,y)\)。水月想把矩阵的所有元素都变成0。她可以一步完成以下操作:选择任意......
  • AtCoder Beginner Contest 317
    A-Potions#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongintpower(intx,inty,intp){x%=p;intans=1;while(y){if(y&1)ans=ans*x%p;y>>=1,x=x*x%p;}......