C. Party Lemonade

这个题目是贪心,开始我以为是背包,不过也不太好背包,因为这个L都已经是1e9了。

这个题目怎么贪心呢?它是因为这里有一个二倍的关系,所以说val[i]=val[i-1]*2

所以利用这个关系,我们可以求出每一个体积的最小的花费。

这个处理完之后,我们就可以开始处理题目中的L了。

这个L,从高位开始枚举,先求出L个中最多并且要小于等于这个最大值可以用的这个物品的数量,然后如果是小于,那么再多选一次,这样肯定会超出体积,

不过这样就保证了大于等于L。

对于下面一个L取完膜之后继续这样处理,最后求出最小值。

#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
ll val[]; int main()
{
int n;
ll L;
scanf("%d%I64d", &n, &L);
for (int i = ; i <= n; i++) scanf("%I64d", &val[i]);
for (int i = ; i <= n; i++) val[i] = min(val[i], val[i - ] * );
ll ans = inf64, sum = ;
for(int i=n;i>=;i--)
{
ll len = << (i - );
ll num = L / len;
sum += num * val[i];
L %= len;
ans = min(ans, sum + (L > )*val[i]);
}
printf("%I64d\n", ans);
return ;
}

C

B. Dima and a Bad XOR

这个题目其实比较简单,就是找规律,如果找出来了,就很简单了。

首先我发现如果每一行有两个不同的数,那么肯定是可以的,然后lj发现如果最后一行有两个不相同的数,那么肯定也是可以的,最后就可以推出来

如果任意一行有两个数不同,那么肯定也是可以的。

这样子就很简单了。

#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e5 + ;
int mp[][]; int main() {
int n, m;
scanf("%d%d", &n, &m);
int flag = , mark = ;
for (int i = ; i <= n; i++) {
for (int j = ; j <= m; j++) {
scanf("%d", &mp[i][j]);
if (!flag&&j > && mp[i][j] != mp[i][]) {
flag = i;
mark = j;
}
}
}
if (!flag)
{
int ans = ;
for (int i = ; i <= n; i++) ans ^= mp[i][];
if (ans == ) printf("NIE\n");
else
{
printf("TAK\n");
for (int i = ; i < n; i++) printf("1 ");
printf("1\n");
}
}
else
{
printf("TAK\n");
int ans = ;
for (int i = ; i <= n; i++) ans ^= mp[i][];
if(ans)
{
for (int i = ; i < n; i++) printf("1 ");
printf("1\n");
}
else
{
for(int i=;i<=n;i++)
{
if (i == flag) printf("%d ", mark);
else printf("1 ");
}
printf("\n");
}
}
return ;
}

B

J 牛客假日团队赛1 分组

这个题目其实很不好想,这个是lj一步步引导我才写出来的,

首先这个题目每一个位置可以往后面推出 1~k 所以算一下复杂度是1e7

dp[i]表示以 i 为最后一个值,从 1~i 的最大的分完组之后的和。

所以这个就有刷表法和填表法,

就是从这个状态往后推和每一个状态从前面推过来,第一个很好写,后面那个比较难。

#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e4 + ;
int dp[maxn];
int a[maxn]; int main()
{
int n, k;
scanf("%d%d", &n, &k);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i=;i<=n;i++)
{
int mxx = ;
for(int j=;j<=k;j++)
{
if (i + j > n) break;
mxx = max(mxx, a[i + j]);
dp[i + j] = max(dp[i + j], dp[i] + j * mxx);
//printf("i=%d j=%d dp[%d]=%d\n", i, j, i + j, dp[i + j]);
}
}
printf("%d\n", dp[n]);
return ;
}

1

#include <cstdio>
#include <cstring>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>
#define inf 0x3f3f3f3f
#define inf64 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn = 1e4 + ;
int dp[maxn];
int a[maxn]; int main()
{
int n, k;
scanf("%d%d", &n, &k);
for (int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i=;i<=n;i++)
{
int mxx = ;
for(int j=;j<k;j++)
{
if (i < j + ) break;
mxx = max(mxx, a[i - j]);
dp[i] = max(dp[i],dp[i - j - ] + mxx * (j + ));
// printf("i=%d j=%d dp[%d]=%d dp[%d]=%d\n", i, j, i, dp[i],i-j,dp[i-j]);
// printf("mxx=%d\n", mxx);
}
}
printf("%d\n", dp[n]);
return ;
}

2

dp 20190618的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. Eclipse中实现JS代码提示功能

    转发: 用Eclipse写js代码时没有提示,很烦,心累: 找个各种方法以及插件,试了一下,个人感觉AngularJS Eclipse 插件很强,好用,不多说,先装上: 然后重启Eclipse ,右键 ...

  2. zepto+mui开发中的tap事件重复执行

    zepto.js和mui一起使用的时候,因为都有tap事件绑定tab事件后会多次触发还会报错,这时不引用zepto中的touch.js就可以了,只用mui的tap相关事件. $(function () ...

  3. Lightoj1093 【线段树】

    题意: 给出n个数,然后对于D区间的数求一个最大差值 思路: 区间最大最小...我居然没想到线段树... #include <bits/stdc++.h> using namespace ...

  4. C# interface 的特性 无法被implement class继承

    最近做interface添加特性后,implement class 无法继承. 微软要求class是实现Interface而不是继承,所以我们必须手动添加特性,而不能自动继承. 对于abstract ...

  5. LeetCode.905-按奇偶排序数组(Sort Array By Parity)

    这是悦乐书的第347次更新,第371篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第212题(顺位题号是905).给定一个非负整数数组A,返回一个由A的所有偶数元素组成的 ...

  6. C#字体字号的改变

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  7. Validation(2)

    站在巨人的肩膀上 spring注解式参数校验 2016年06月15日 15:42:47 God_Ming 阅读数:57021 标签: springhibernatevalidator 更多 个人分类: ...

  8. 黑马tomact学习一 tomcat下载 安装和卸载

  9. iOS开发 - 多线程实现方案之Pthread篇

    pthread基础 pthread是POSIX thread的简写,一套通用的多线程API,适用于Unix.Linux.Windows等系统,跨平台.可移植,使用难度大,C语言框架,线程生命周期由程序 ...

  10. wireshark工具集

    tshark 查看pcap文件第一个包的时间,当文件名不包含时间信息时非常有帮助 tshark -c 1 -T fields -e frame.time -r test.pcap dumpcap ed ...