Codeforces 1132 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1132
A - Regular Bracket Sequence - [水]
题解:首先 "()" 这个的数量多少是没有关系的,但是 "((" 和 "))" 的数量必须是相等的,再然后如果存在 ")(" 的话,"((" 和 "))" 的数目就必须要大于零。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main()
{
cin>>a>>b>>c>>d;
if(a==d)
{
if(c> && a== && d==) cout<<<<endl;
else cout<<<<endl;
}
else cout<<<<endl;
}
B - Discounts - [水]
题意:有 $n$ 块巧克力,每个价格为 $a[i]$,你必须把它们都买完。现在你有 $m$ 张优惠券,一张优惠券可以使你买任意 $q[i]$ 块巧克力并让你免去其中最便宜的那块巧克力的钱,剩下的都要全款买下。你要给出用每张优惠券买完所有巧克力的最少花费。
题解:很显然,如果一张优惠券只能买一块巧克力是最好的,能免去最贵的那块巧克力的钱;能买两个的次之,能免去次贵的巧克力的钱;以此类推。
AC代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=3e5+;
int n,m,a[maxn];
int main()
{
scanf("%d",&n);
ll sum=;
for(int i=;i<=n;i++) scanf("%d",&a[i]), sum+=a[i];
sort(a+,a+n+,greater<int>{});
scanf("%d",&m);
for(int i=,q;i<=m;i++)
{
scanf("%d",&q);
printf("%I64d\n",sum-a[q]);
}
}
C - Painting the Fence- [前缀和优化]
D - Stressful Training - [二分+贪心+优先队列]
E - Knapsack - [DFS]
网上看题解,居然可以搜过去?有点神仙啊……
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; ll w,a[],ans;
void dfs(int p,ll x)
{
if(p==)
{
ans=max(ans,x);
return;
}
ll v=min((w-x)/p,a[p]);
for(int t=;t>;t--) dfs(p+,x+max(0LL,(v--)*p));
}
int main()
{
cin>>w;
for(int i=;i<=;i++) cin>>a[i];
dfs(,);
cout<<ans<<endl;
}
F - Clear the String - [区间DP]
题解:设 $f[l][r]$ 是消除 $[l,r]$ 区间所花的最少次数,对于每次更新:
1、如果 $s[l]=s[r]$,$f[l][r]=min(f[l][r],f[l+1][r−1]+1)$;
2、如果 $s[l] \neq s[r]$,$f[l][r]=min(f[l][r],min(f[l+1][r],f[l][r−1])+1)$
3、枚举中间点 $k=l \sim r$,$f[l][r]=min(f[l][r],f[l][k]+f[k][r]−1)$,这样的话 $k$ 这个点删了两次,所以要减一,因为 $l,k,r$ 可能被同时删去,所以要这样转移。
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=;
int n;
char s[maxn];
int f[maxn][maxn]; int main()
{
cin>>n;
scanf("%s",s+); memset(f,,sizeof(f));
for(int i=;i<=n;i++) f[i][i]=;
for(int len=;len<=n;len++)
{
for(int i=,j=i+len-;j<=n;i++,j++)
{
f[i][j]=INF;
if(s[i]==s[j]) f[i][j]=min(f[i][j],f[i+][j-]+);
else f[i][j]=min(f[i][j],min(f[i+][j],f[i][j-])+);
for(int k=i;k<=j;k++) f[i][j]=min(f[i][j],f[i][k]+f[k][j]-);
}
}
cout<<f[][n]<<endl;
}
Codeforces 1132 - A/B/C/D/E/F - (Undone)的更多相关文章
- Codeforces 1114 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1114 A - Got Any Grapes? 题意:甲乙丙三个人吃葡萄,总共有三种葡萄:绿葡萄.紫葡萄和黑葡萄,甲乙丙三个人至少要 ...
- Codeforces 1043 - A/B/C/D/E/F - (Undone)
链接:http://codeforces.com/contest/1043 A - Elections - [水水水水题] 题意: 我和另一个人竞争选举,共有 $n$ 个人投票,每个人手上有 $k$ ...
- Codeforces 1100 - A/B/C/D/E/F - (Undone)
链接:https://codeforces.com/contest/1100 A - Roman and Browser - [暴力枚举] 题意:浏览器有 $n$ 个网页,编号 $1 \sim n$, ...
- Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings
Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...
- Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块
Educational Codeforces Round 71 (Rated for Div. 2)-F. Remainder Problem-技巧分块 [Problem Description] ...
- codeforces#1132 F. Clear the String(神奇的区间dp)
题意:给出一个字符串S,|S|<=500.每次操作可以删除一段连续的相同字母的子串.问,最少操作多少次可以把这个字符串变成空串. 分析:刚开始的思路是,把连续的串给删除掉,然后再....贪心.完 ...
- Codeforces Bubble Cup 8 - Finals [Online Mirror] F. Bulbo DP
F. Bulbo Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/575/problem/F Des ...
- Codeforces 1154 - A/B/C/D/E/F/G - (Undone)
链接:https://codeforces.com/contest/1154 A - Restoring Three Numbers - [水] #include<bits/stdc++.h&g ...
- Educational Codeforces Round 58 (Rated for Div. 2) F dp + 优化(新坑) + 离线处理
https://codeforces.com/contest/1101/problem/F 题意 有n个城市,m辆卡车,每辆卡车有起点\(s_i\),终点\(f_i\),每公里油耗\(c_i\),可加 ...
随机推荐
- SCF: 简单配置门面[转]
原文:https://blog.csdn.net/koqizhao/article/details/82178100 Simple Configuration Facade :简单配置门面 是 代码 ...
- centos7.0安装cuda驱动
00.CUDA简介 CUDA和GPU的并行处理能力来加速深度学习和其他计算密集型应用程序 01.CPU+GPU协同架构 02.部署环境 [docker@lab-250 ~]$ cat /etc/*re ...
- utf-8 编码问题
使用下面直接进行处理$str = preg_replace('/[\x{10000}-\x{10FFFF}]/u', '', $str);
- Spring Boot系列——死信队列
在说死信队列之前,我们先介绍下为什么需要用死信队列. 如果想直接了解死信对接,直接跳入下文的"死信队列"部分即可. ack机制和requeue-rejected属性 我们还是基于上 ...
- csproj文件中copy指令的使用方式
实际开发中有很多项目需要引用第三方的dll或者资源文件,且文件比较多,在运行时这些文件需要被拷贝到BIN目录. 使用VS自带的"复制到输出目录",似然方便,但是比较不零活,经过多次 ...
- [MySQL Status] Queries,Questions,read/s区别,Com_Commit和handle_commit
Queries: 这个状态变量表示,mysql系统接收的查询的次数,包括存储过程内部的查询 Questions: 这个状态变量表示,mysql系统接收查询的次数,但是不包括存储过程内部的查询 ...
- web多站点跨域访问
有时项目app和m 需要公用一套接口 这个时候就要用到跨域:特别是app接口跨域访问站点时. 跨域配置: 1.iis服务器上需要安装URLwrite2.0 2.web.config 需要添加这个配置: ...
- MongoDB 查询总结
1.含日期查询 从起始时间到结束时间 BasicDBObject queryObj = new BasicDBObject(); queryObj.put("date",new B ...
- python pyenv
使用pyenv安装多个版本的python 管理多个python环境使用 virtualenv 请看 http://www.cnblogs.com/juandx/p/5357518.html 安装py ...
- R语言扩展包dplyr——数据清洗和整理
R语言扩展包dplyr——数据清洗和整理 标签: 数据R语言数据清洗数据整理 2015-01-22 18:04 7357人阅读 评论(0) 收藏 举报 分类: R Programming(11) ...