Link:

Codeforces #210 传送门

A:

贪心,对每个值都取最大值,不会有其他解使答案变优

#include <bits/stdc++.h>

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int,int> P;
typedef double db;
const int MAXN=,INF=<<;
struct data{int op,l,r,x;}dat[MAXN];
int n,m,mx[MAXN],vis[MAXN]; int main()
{
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++)
scanf("%d%d%d%d",&dat[i].op,&dat[i].l,&dat[i].r,&dat[i].x);
for(int i=;i<=n;i++)
{
int tmp=;mx[i]=INF;
for(int j=;j<=m;j++)
if(dat[j].op==&&i>=dat[j].l&&i<=dat[j].r)
tmp+=dat[j].x;
else if(dat[j].op==&&i>=dat[j].l&&i<=dat[j].r)
mx[i]=min(mx[i],dat[j].x-tmp);
}
for(int i=;i<=n;i++)
{
if(mx[i]==INF) mx[i]=;
int tmp=mx[i];
for(int j=;j<=m;j++)
if(dat[j].op==&&i>=dat[j].l&&i<=dat[j].r)
tmp+=dat[j].x;
else if(dat[j].op==&&i>=dat[j].l&&i<=dat[j].r&&tmp==dat[j].x)
vis[j]++;
}
for(int i=;i<=m;i++)
if(dat[i].op==&&!vis[i]) return puts("NO"),;
puts("YES");
for(int i=;i<=n;i++)
printf("%d ",mx[i]);
return ;
}

Problem A

B:

答案可行性单调,二分答案

每次判断用$dp[i]$表示到$i$只要要删多少个数,$i$必取

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=2e3+;
int n,k,l,r,dat[MAXN],dp[MAXN]; bool check(int x)
{
int ret=n;
for(int i=;i<=n;i++) dp[i]=i-;
for(int i=;i<=n;i++)
for(int j=;j<i;j++)
if(abs(dat[i]-dat[j])<=1ll*x*(i-j))
dp[i]=min(dp[i],dp[j]+i-j-);
for(int i=;i<=n;i++)
ret=min(ret,dp[i]+n-i);
return ret<=k;
} int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++) scanf("%d",&dat[i]);
l=;r=2e9;
while(l<=r)
{//注意爆long long
int mid=l/+r/+(l%+r%)/;
if(check(mid)) r=mid-;
else l=mid+;
}
printf("%d",l);
return ;
}

Problem B

$i$必取这个条件一定要加,否则无法转移

同时注意二分时$l+r$可能爆$longlong$

C:

想到从前往后$dp$,每次按以$i$为左端点时对答案的贡献转移

但这样在$t[i]=s[i]$时是后项相关的,不符合$dp$要求

因此要将$t[i]=s[i]$合并在$t[i]>s[i]$中计算,$t[i]>s[i]$时的贡献变为$(pre+1)*(n-i+1)$

$dp[i][j]$:以前$i$位为左端点结果为$j$的方案数,分$t[i]>s[i]$与$t[i]<s[i]$枚举$pre$转移

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int MAXN=2e3+,MOD=1e9+;
int n,k;char s[MAXN];
ll pre[MAXN][MAXN],dp[MAXN][MAXN]; int main()
{
scanf("%d%d%s",&n,&k,s+);
dp[][]=pre[][]=;
for(int i=;i<=n;i++)
for(int j=;j<=k;j++)
{
dp[i][j]=pre[i-][j]*(s[i]-'a')%MOD;
for(int k=;(k+)*(n-i+)<=j&&k<i;k++)
(dp[i][j]+=dp[i-k-][j-(k+)*(n-i+)]*('z'-s[i]))%=MOD;
pre[i][j]=(pre[i-][j]+dp[i][j])%MOD;
}
printf("%lld",pre[n][k]);
return ;
}

Problem C

[Codeforces #210] Tutorial的更多相关文章

  1. [Codeforces #172] Tutorial

    Link: Codeforces #172 传送门 A: 一眼看上去分两类就可以了 1.每个矩形只有两条边相交,重合的形状为菱形 2.每个矩形四条边都有相交 对于情况1答案为$h*h/sin(a)$ ...

  2. [Codeforces #514] Tutorial

    Link: Codeforces #514 传送门 很简单的一场比赛打崩了也是菜得令人无话可说…… D: 一眼二分,发现对于固定的半径和点,能包含该点的圆的圆心一定在一个区间内,求出区间判断即可 此题 ...

  3. [Codeforces #196] Tutorial

    Link: Codeforces #196 传送门 A: 枚举 #include <bits/stdc++.h> using namespace std; #define X first ...

  4. [Codeforces #174] Tutorial

    Link: Codeforces #174 传送门 A: 求原根的个数,有一条性质是原根个数为$\phi(\phi(n))$,多了一个不会证的性质 如果要确定哪些是原根的话还是要枚举,不过对于每个数不 ...

  5. [Codeforces #190] Tutorial

    Link: Codeforces #190 传送门 A: 明显答案为$n+m-1$且能构造出来 #include <bits/stdc++.h> using namespace std; ...

  6. [Codeforces #211] Tutorial

    Link: Codeforces #211 传送门 一套非常简单的题目,但很多细节都是错了一次才能发现啊…… 还是不能养成OJ依赖症,交之前先多想想corner case!!! A: 模拟,要特判0啊 ...

  7. [Codeforces #192] Tutorial

    Link: Codeforces #192 传送门 前两天由于食物中毒现在还要每天挂一天的水 只好晚上回来随便找套题做做找找感觉了o(╯□╰)o A: 看到直接大力模拟了 但有一个更简便的方法,复杂度 ...

  8. [Codeforces #201] Tutorial

    Link: 传送门 代码量很少的一套思维题 A: 试一试发现最后状态一定是所有$min,max$间$gcd$的倍数 直接判断数量的奇偶性即可 #include <bits/stdc++.h> ...

  9. [Codeforces #188] Tutorial

    Link: Codeoforces #188 传送门 A: 先全转为正数,后面就全是指数级增长了 #include <bits/stdc++.h> using namespace std; ...

随机推荐

  1. 【转】IOS版本自定义字体步骤

    本文转载自:http://quick.cocoachina.com/wiki/doku.php?id=ios%E7%89%88%E6%9C%AC%E4%BD%BF%E7%94%A8%E8%87%AA% ...

  2. Exponial (欧拉定理+指数循环定理+欧拉函数+快速幂)

    题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=2021 Description Everybody loves big numbers ...

  3. Android 6.0 Marshmallow root 方法

    android 6.0 已经推出 release 版本了, nexus 5,6,7,9 都放了官方镜像, 本篇文章使用 nexus 6 安装最新的 android 6.0 并进行root step 1 ...

  4. in_device结构和in_ifaddr结构

    /* ip配置块 */ struct in_device { /* 二层设备 */ struct net_device *dev; /* 引用计数 */ atomic_t refcnt; /* 是否正 ...

  5. python基础===self的理解

    self是类的实例 self有点类似java中的this,无实际意义.但是约定俗成的都是用self表示类的实例 class A: def func(self): print(self) #指向的是类的 ...

  6. Linux内核死锁检测机制【转】

    转自:http://www.oenhan.com/kernel-deadlock-check 死锁就是多个进程(线程)因为等待别的进程已占有的自己所需要的资源而陷入阻塞的一种状态,死锁状态一旦形成,进 ...

  7. 下载 LFS所需要的源码包的脚本程序及检验方法

    下载 LFS所需要的源码包的脚本程序及检验方法 http://blog.csdn.net/yygydjkthh/article/details/45315143

  8. pxc群集搭建

    pxc群集搭建 1.环境 Percona-XtraDB 5.7.22-22-29.26-log percona-xtrabackup-24-2.4.12 192.168.99.210:3101(第一节 ...

  9. 项目评审ppt的纲要

    1.prd不能模糊,产品的问题全部明确 2.收益在哪里 3.设计体现业务4.怎样保证数据的前后协作5.异常如何处理6.技术解决的痛点7.对外部依赖8.性能指标预期(响应时间)9.

  10. HDU 5627 Clarke and MST &意义下最大生成树 贪心

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5627 题意:Bestcoder的一道题,让你求&意义下的最大生成树. 解法: 贪心,我们从高位 ...