Good Bye 2014 F - New Year Shopping
对于一种特殊的不可逆的dp的拆分方法。。
也可以用分治写哒。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PII pair<int, int>
#define y1 skldjfskldjg
#define y2 skldfjsklejg using namespace std; const int N = + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ; int n, p, c[N], h[N], t[N], L[][N], dp[N], a[], b[], ans[]; vector<int> v[];
vector<int> qus[]; void solve(int T) {
int down = max(T - p + , ), up = min(, T + p - );
memset(dp, , sizeof(dp));
for(int k = T - ; k >= down; k--) {
for(int id : v[k]) {
for(int j = N - ; j >= c[id]; j--)
dp[j] = max(dp[j - c[id]] + h[id], dp[j]);
}
memcpy(L[k - down], dp, sizeof(dp));
}
memset(dp, , sizeof(dp));
for(int k = T; k <= up; k++) {
for(int id : v[k]) {
for(int j = N - ; j >= c[id]; j--)
dp[j] = max(dp[j - c[id]] + h[id], dp[j]);
}
for(int x : qus[k]) {
for(int j = ; j <= b[x]; j++)
ans[x] = max(ans[x], dp[j] + L[k - T][b[x] - j]);
}
}
} int main() {
scanf("%d%d", &n, &p);
for(int i = ; i <= n; i++) {
scanf("%d%d%d", &c[i], &h[i], &t[i]);
v[t[i]].push_back(i);
}
int q; scanf("%d", &q);
for(int i = ; i <= q; i++) {
scanf("%d%d", &a[i], &b[i]);
qus[a[i]].push_back(i);
} for(int i = ; i <= ; i += p) {
solve(i);
} for(int i = ; i <= q; i++) printf("%d\n", ans[i]);
return ;
} /*
*/
Good Bye 2014 F - New Year Shopping的更多相关文章
- Hello world,Hello 2015,Bye 2014
序 在我写下“在”这个字的时候已经是2014-12-31 19:59,14年最后一天了,总觉得不写点东西祭奠一下那些被自己虐死的脑细胞,心里就不舒服. 那就从生活,工作,学习三个方面,总结一下吧. 生 ...
- Good Bye 2014 D. New Year Santa Network 图论+期望
D. New Year Santa Network New Year is coming in Tree World! In this world, as the name implies, th ...
- Good Bye 2015 F - New Year and Cleaning
F - New Year and Cleaning 这题简直是丧心病狂折磨王.. 思路:容易想到这样一个转换,把整个矩形一起移动,矩形移出去的时候相当于一行或者一列. 为了优化找到下一个消去的点,我先 ...
- Good Bye 2014 B. New Year Permutation(floyd )
题目链接 题意:给n个数,要求这n个数字小的尽量放到前面,求一个最小的. 给一个矩阵s[i][j]==1,表示位置 i 的数字可以和 位置 j 的数字交换. 分析: 刚开始用的是3个循环,每次都找一个 ...
- CodeForces Good Bye 2014 B. New Year Permutation
可能是因为这次没有分Div.1和Div.2,所以感觉题的难度比较大. 题意: 给出一个1~n的排列和一个邻接矩阵A,Aij = 1表示可以交换排列的第i项和第j项,问经过若干次交换后,求能够得到最小字 ...
- Good Bye 2016 F.New Year and Finding Roots(交互)
题目链接 \(Description\) 有一棵高度为\(h\)的满二叉树,点从\(1\)到\(2^h-1\)编号(无序).每次你可以询问一个点的编号,交互库会返回其所有邻接点的编号.你需要在\(16 ...
- Good Bye 2014 E - New Year Domino 单调栈+倍增
E - New Year Domino 思路:我用倍增写哒,离线可以不用倍增. #include<bits/stdc++.h> #define LL long long #define f ...
- Good Bye 2014 B. New Year Permutation 【传递闭包 贪心】
解题思路:给出一列数an,再给出一个矩阵d[i][j],在满足d[i][j]=1的情况下,称a[i]和a[j]可以交换,问经过交换最后得到字典序最小的数列a[n] 首先是贪心的思想,大的能换就换到后面 ...
- 多线程、多进程、协程、缓存(memcache、redis)
本节内容: 线程: a:基本的使用: 创建线程: 1:方法 import threading def f1(x): print(x) if __name__=='__main__': t=thread ...
随机推荐
- Windows互斥锁demo和分析
一:windows创建锁接口 创建互斥锁的方法是调用函数CreateMutex HANDLE CreateMutex( LPSECURITY_ATTRIBUTESlpMutexAttributes, ...
- source 导入文件
有时候,phpmyadmin 导入 是有大小限制的: 只可以用sql命令的source来导入文件
- socket--粘包
参考博客:http://www.cnblogs.com/kex1n/p/6502002.html 一.粘包现象 在上一篇的socket传输大数据文章中,我们可以顺利的接发数据,似乎做的不错,可以接收了 ...
- Order By 问题集合
问题(一):Order By 多个参数排序 在做多字段的排序的时候我们经常会会用到该语句. 所以多参数排序是从左到右的局部排序,修改的范围只有前面参数(几个参数)相同的情况下在排序. select * ...
- 2017北京国庆刷题Day6 afternoon
期望得分:100+100+40=240 实际得分:100+0+40=140 二进制拆分.二进制前缀和 #include<cstdio> #include<iostream> u ...
- [USACO14JAN]Recording the Moolympics
题目描述 Being a fan of all cold-weather sports (especially those involving cows), Farmer John wants to ...
- bzoj 2453: 维护队列
2453: 维护队列 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1079 Solved: 503[Submit][Status][Discuss ...
- POJ 1389 Area of Simple Polygons 扫描线+线段树面积并
---恢复内容开始--- LINK 题意:同POJ1151 思路: /** @Date : 2017-07-19 13:24:45 * @FileName: POJ 1389 线段树+扫描线+面积并 ...
- Python学习笔记(五十)爬虫的自我修养(三)爬取漂亮妹纸图
import random import urllib from urllib import request import os ################################### ...
- CSS浏览器兼容问题集-第二部分
11.高度不适应 高度不适应是当内层对象的高度发生变化时外层高度不能自动进行调节,特别是当内层对象使用margin 或paddign 时. 例: #box {background-color:# ...