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\),可加 ...
随机推荐
- MySQL导出TSV格式文件
可以使用mysqldump, 也可以使用mysql -e 使用mysqldump 因为要使用到 -T / --tab 参数, 需要先查看mysql设置的secure_file_priv mysql&g ...
- sql 有条件计数
select InstitutionID=LEFT(InstitutionID,9), Irregularities_Type=sum(CASE WHEN Irregularities_Type> ...
- Atitit 关于共享经济之共享男女朋友的创业计划
Atitit 关于共享经济之共享男女朋友的创业计划 1. 共享经济的历史与趋势 1 1.1. 共享经济三大特征=产能过剩+共享平台+人人参与. 1 1.2. 共享经济是个大趋势,使用权渐渐的取代所有权 ...
- WWDC 17: 开发者的最初观感
WWDC 17: 开发者的最初观感 前言 每年的 WWDC 都是 iOS 开发者集体高潮的时刻.第一天的 WWDC 带来了全新的 iOS 11.MacOS.tvOS 和 watchOS,革命性的 AR ...
- const的位置问题
来源:牛客网 下列哪两个是等同的 int b; 1.const int *a = &b; 2.const * int a = &b; 3.const int* const a = &a ...
- Groovy 和 Gradle
0.Groovy和Gradle是什么关系? Gradle,自动化构建工具,通过简单编写Groovy脚本,便可进行依赖管理并完成项目构建: 1. Groovy有什么用? 脚本+Java代码: 2. Gr ...
- application.properties详解 --springBoot配置文件【转载】
# spring boot application.properties配置的各个属性详解 # 该示例文件作为标准提供.(官方文档 翻译过来的) # 还是花了些功夫翻译,各位如果转发,请留下本文地址, ...
- 【转】WPF Template模版之DataTemplate与ControlTemplate(一)
WPF系统不但支持传统的Winfrom编程的用户界面和用户体验设计,更支持使用专门的设计工具Blend进行专业设计,同时还推出了以模板为核心的新一代设计理念. 1. 模板的内涵 作为表现形式,每个控件 ...
- 在java.util中有EventListener接口:所有事件监听者都要实现这个接口。
在java.util中有EventListener接口:所有事件监听者都要实现这个接口. java.util中有EventObject类:所有的事件都为其子类. 事件范例在\CoreJava\Gi ...
- Adding ASP.NET MVC5 Identity Authentication to an existing project
Configuring Identity to your existing project is not hard thing. You must install some NuGet package ...