当前位置:网站首页>The 16th Heilongjiang Provincial Collegiate Programming Contest
The 16th Heilongjiang Provincial Collegiate Programming Contest
2022-06-30 21:09:00 【WDLieqi】
目录
D - Doin’ Time
题目思路
可以作为练习区间dp的改后的模板题。题目代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 310;
const int mod = 1000003;
int n;
LL p[N];
LL s[N][N], f[N][N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++)
cin >> p[i];
for (int i = 1; i <= n; i ++)
{
LL t = 1;
for (int j = i; j <= n; j ++)
t = (t * p[j]) % mod, s[i][j] = t;
}
for (int len = 2; len <= n; len ++)
{
for (int i = 1; i + len - 1 <= n; i ++)
{
int l = i, r = i + len - 1;
f[l][r] = -1;
for (int k = l; k < r; k ++)
{
f[l][r] = max(f[l][r], f[l][k] + f[k + 1][r] + (s[i][k] - s[k + 1][r]) * (s[i][k] - s[k + 1][r]));
}
}
}
cout << f[1][n] << '\n';
return 0;
}
J - JOJO’s Factory
题目思路
因为题目已经给了M的范围即 小于等于2 * n - 3,所以我们可以得出一定不会有像
4 6
1 1
1 2
1 3
2 1
2 2
2 3
这样的数据,所以就可以得出只要不是A里面匹配了n个B就一定可以全部配对。
题目代码
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
const int N = 5e5 + 10;
int ma[N], mb[N], n, m;
void solve()
{
cin >> n >> m;
int a = n, b = n;
while (m -- )
{
int x, y;
cin >> x >> y;
ma[x] ++;
mb[y] ++;
if (ma[x] >= n)
a --;
if (mb[y] >= n)
b --;
}
cout << min(a, b) << '\n';
}
int main()
{
IOS // 不加会超时
int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
K. Keep Eating
题目思路
我们可以先将全部的重量合起来 sum,然后一次就吃1重量,最后剩下k个,就直接吃 k / 2 就可以了,注意特判一下 sum 是否大于 k。
题目代码
#include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
void solve()
{
LL n, k;
cin >> n >> k;
LL res1 = 0, res2 = 0;
for (int i = 0; i < n; i ++)
{
int x;
cin >> x;
res1 += x;
}
if (res1 < k)
{
cout << 0 << '\n';
return;
}
res2 += res1 - k + k / 2;
cout << res2 << '\n';
}
int main()
{
IOS int T = 1;
//cin >> T;
while (T--)
{
solve();
}
return 0;
}
边栏推荐
- CentOS - enable / disable Oracle
- 两个skyline
- Lumiprobe cell biology - dia, instructions for lipophilic tracer
- Deflection lock / light lock / heavy lock lock is healthier. How to complete locking and unlocking
- MFC界面库BCGControlBar v33.0 - 桌面警报窗口、网格控件升级等
- oprator-1初识oprator
- 19.04 分配器
- 利用日志服务器输出各种apache的日志的TOPN
- Scene 299
- Huffman tree (I) basic concept and C language implementation
猜你喜欢

开发技术-使用easyexcel导入文件(简单示例)

Lvalue reference and lvalue reference

Testing principle and precautions of biovendor rage ELISA Kit

MySQL introduction, detailed installation steps and usage | dark horse programmer

Huffman tree (I) basic concept and C language implementation

偏向锁/轻量锁/重级锁锁锁更健康,上锁解锁到底是怎么完成实现的

Basic components of STL

文本生成模型退化怎麼辦?SimCTG 告訴你答案

Iclr'22 spotlight | how to measure the amount of information in neural network weights?

Lumiprobe dye hydrazide - BDP FL hydrazide solution
随机推荐
Peking University ACM problems 1004:financial management
Digital currency: far-reaching innovation
双立体柱状图/双y轴
SqlServer 获取字符串中数字,中文及字符部分数据
uniapp怎么上传二进制图片
Study on PEGylation of lumiprobe and PEG linker - iodine-peg3-acid
文本生成模型退化怎么办?SimCTG 告诉你答案
【等级测评师】等级测评师怎么报名?多少分及格?
翻转链表II[翻转链表3种方式+dummyHead/头插法/尾插法]
【微服务~Nacos】Nacos之配置中心
毕业五年,想当初若没有入行测试,我是否还会如这般焦虑
MySQL:SQL概述及数据库系统介绍 | 黑马程序员
ssh-server配置文件参数PermitRootLogin介绍
How to move forward when facing confusion in scientific research? How to give full play to women's advantages in scientific research?
文本生成模型退化怎麼辦?SimCTG 告訴你答案
Markdown笔记简明教程
Peking University ACM problems 1002:487-3279
MySQL简介、详细安装步骤及使用 | 黑马程序员
加密与解密以及OpenSSL的应用
Radar data processing technology