2019牛客暑期多校训练营(第二场)[ADFH]

问题虫洞——A:Eddy Walker 在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 1009
#define INF 0x3f3f3f3f//将近ll类型最大数的一半,而且乘2不会爆ll
const ll mod = 1000000007;

ll inv(ll b){ return b == 1? 1: (mod-mod/b)*inv(mod%b)%mod;}//递推求乘法逆元
//ll (ll a, ll b)
//{
//    ll ans = 1;
//    while(b){
//        if(b&1)
//            ans = ans*a%mod;
//        a = a*a%mod;
//        b>>=1;
//    }
//    return ans;
//}
//int main()
//{
//    ll ans = (n-1, mod-2);
//}
int main()
{
   ll t, ans=1;
   cin >> t;
   while(t--){
    ll n, m;
    cin >> n >> m;
    if(n == 1) ans = ans;
    else {
        if(m == 0) ans=0;
        else ans = ans*inv(n-1)%mod;
    }
    cout << ans << '\n';
   }
    return 0;
}


问题虫洞——D:Kth Minimum Clique

题意:

给你一个有n个点我无向图邻接矩阵,给出每个点的权值,求第k小的完全子图(空集是最小的完全子图)

来来来,推荐一篇好看的博客:牛客网多校训练第二场D Kth Minimum Clique

(还有,师哥说我头文件恶心,恶心嘛?恶心嘛?不恶心啊。标准右对齐好嘛)

//#include<bits/stdc++.h>
#include  <stdio.h>
#include <iostream>
#include<algorithm>
#include      <map>
#include   <bitset>
#include   <vector>
#include    <queue>
#include    <stack>
#include <stdlib.h>
#include  <cstring>
#include <string.h>
#include   <string>
#include   <math.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f//将近ll类型最大数的一半,而且乘2不会爆ll
const ll mod = 1000000007;
const int MAXN = 1e6 + 5;

int n, k;
ll val[105];
bitset<105>stu[105];
struct node
{
    ll w;
    int id;//记录当前团最后加入的点编号,当前团只加入最后加入点之后的点,达到去重的目的
    bitset<105>clique;
    friend bool operator<(const node&a, const node&b)
    {
        return a.w > b.w;
    }
};
priority_queue<node>q;
int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; ++i)
        scanf("%lld", &val[i]);
    int x;
    for(int i=1 ; i<=n; ++i)
        for(int j=1; j<=n; ++j)
        {
            scanf("%1d", &x);
            stu[i][j] = x;
        }
    ll ans = -1;
    node st;
    st.id = 0;
    st.w = 0;
    q.push(st);
    while(!q.empty())
    {
        node now = q.top();
        q.pop();
        k--;
        if(!k)
        {
            ans = now.w;
            break;
        }
        for(int i=now.id+1; i<=n; ++i)
        {
            if((now.clique&stu[i]) == now.clique)//说明点i与当前团中的点都相连
            {
                node next;
                next.id = i;
                next.clique = now.clique;
                next.clique[i] = 1;
                next.w = now.w + val[i];
                q.push(next);
            }
        }
    }
    cout << ans << '\n';
    return 0;
}


问题虫洞——F:Partition problem

在这里插入图片描述(一个一个往外拉,往外拉,往外拉)

//#include<bits/stdc++.h>
#include  <stdio.h>
#include <iostream>
#include<algorithm>
//#include      <map>
//#include      <set>
//#include   <vector>
//#include    <queue>
//#include    <stack>
#include <stdlib.h>
#include  <cstring>
#include <string.h>
#include   <string>
#include   <math.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f//将近ll类型最大数的一半,而且乘2不会爆ll
const ll mod = 1000000007;
const int MAXN = 1e6 + 5;

int D[30][30], p1[30], p2[30], n, a=0, b=0;
ll ans;
void dfs(int c, ll sum)
{
    if(a+b == n) {ans = max(ans, sum); return;}
    if(a<n/2)
    {
        ll ret = 0;
        p1[a++] = c;
        for(int i=0; i<b; ++i)
            ret+=D[c][p2[i]];
        dfs(c+1, sum+ret);
        a--;
    }
    if(b < n/2)
    {
        ll ret = 0;
        p2[b++] = c;
        for(int i=0; i<a; ++i)
            ret+=D[c][p1[i]];
        dfs(c+1, sum+ret);
        b--;
    }
}
int main()
{
    cin >> n;
    n*=2;
    for(int i=0; i<n; ++i)
        for(int j=0; j<n; ++j)
        scanf("%d", &D[i][j]);
    dfs(0, 0);
    cout << ans << '\n';
    return 0;
}



问题虫洞——H:Second Large Rectangle 在这里插入图片描述

在这里插入图片描述其实比较典型的是单调栈和悬线法,,,,

//#include<bits/stdc++.h>
#include  <stdio.h>
#include <iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define MAXN 1009
#define INF 0x3f3f3f3f//将近ll类型最大数的一半,而且乘2不会爆ll
const ll mod = 1000000007;

int dp[MAXN*2][MAXN*2];
int sum=-1, ans=-1;
int main()
{
    int n, m;
    cin >> n >> m;
    for(int i=1; i<=n; ++i)
        for(int j=1; j<=m; ++j)
        {
            scanf("%1d", &dp[i][j]);
            dp[i][j]+=dp[i-1][j]*dp[i][j];//向上的高度

        }
        for(int i=1; i<=n; ++i)
        for(int j=1; j<=m; ++j)
        {
            int len = dp[i][j], dep=1;
            while(len)
            {
                int cnt = len*dep;
                if(cnt > ans){
                    sum = ans;
                    ans = cnt;
                }
                else if(cnt > sum)
                    sum = cnt;
                len = min(len, dp[i][j-dep]);
                dep++;
            }
        }
        printf("%d\n",  sum == -1? 0: sum);
        return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值