CodeForces 148E Porcelain
来源:互联网 发布:htc刷机救砖软件 编辑:程序博客网 时间:2024/05/29 07:47
题意:第一行给出两个数n,m,n表示下面有n行数据,每行数据可以从前或从后去若干个数,一共取m个数,求取出的n个数和最大值
链接:http://codeforces.com/problemset/problem/148/E
思路:预处理背包,将每行数据预处理,求出每行处理成max_n = ( left_sum_n, right_sum_n, left_right_sum_n ),后面按正常背包处理即可
注意点:无
以下为AC代码:
luminous11148E -12GNU C++11Accepted278 ms796 KB2015-02-07 07:59:222015-02-07 07:59:22
#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <vector>#include <deque>#include <list>#include <cctype>#include <algorithm>#include <climits>#include <queue>#include <stack>#include <cmath>#include <map>#include <set>#include <iomanip>#include <cstdlib>#include <ctime>#define ll long long#define ull unsigned long long#define all(x) (x).begin(), (x).end()#define clr(a, v) memset( a , v , sizeof(a) )#define pb push_back#define mp make_pair#define read(f) freopen(f, "r", stdin)#define write(f) freopen(f, "w", stdout)using namespace std;const double pi = acos(-1);int tmp[100005] = { 0 };int dp[100005] = { 0 };int num[105] = { 0 };int ls[105] = { 0 };int rs[105] = { 0 };int ss[105] = { 0 };int main(){ ios::sync_with_stdio( false ); int m, n; while ( cin >> n >> m ){ int k; clr ( dp, 0 ); clr ( num, 0 ); for ( int i = 0; i < n; i ++ ){ cin >> k; for ( int j = 1; j <= k; j ++ ){ cin >> num[j]; } clr ( ls, 0 ); clr ( rs, 0 ); clr ( ss, 0 ); for ( int p = 1; p <= k; p ++ ){ ls[p] = ls[p-1] + num[p]; } for ( int p = k , p1 = 1; p > 0; p --, p1 ++ ){ rs[p1] = rs[p1-1] + num[p]; } for ( int p = 1; p <= k; p ++ ){ ss[p] = max ( ss[p], rs[p] ); ss[p] = max ( ss[p], ls[p] ); } for ( int a = 1; a <= k; a ++ ){ for ( int b = 1; b <= k; b ++ ){ if ( a + b <= k ){ ss[a+b] = max ( ss[a+b], ls[a] + rs[b] ); } } } clr ( tmp, 0 ); memcpy ( tmp, dp, sizeof( dp ) ); for ( int a = 1; a <= k; a ++ ){ for ( int p = m; p >= a; p -- ){ dp[p] = max ( dp[p], tmp[p-a] + ss[a] ); } } } cout << dp[m] << endl; } return 0;}
0 0
- Codeforces 148E(Porcelain)
- Codeforces 148E. Porcelain
- CodeForces 148E Porcelain
- codeforces-148E Porcelain
- CodeForces 148E – Porcelain
- codeforces 148E Porcelain (dp)
- codeforces-148E-Porcelain【DP】
- Codeforces 148 E Porcelain【dp】
- Codeforces 148 E Porcelain dp
- codeforces 148E Porcelain 多重背包
- Codeforces 148E Porcelain [预处理+dp背包]
- Codeforces 148E. Porcelain【多重背包】
- CodeForces 148E Porcelain dp+背包(水
- codeforces 148E Porcelain(DP, 分组背包)
- CodeForces 148E Porcelain(dp+背包)
- Codeforces 148E Porcelain (dp)
- Codeforces 148E Porcelain (预处理+多重背包)
- Codeforces Round #105 (Div. 2)--E. Porcelain 01背包
- 腾讯云 CentOS6.2 64位 NFS 安装
- 810 - A Dicey Problem
- 黑马程序员————IOS学习笔记 第11篇 经典示例计算代码行数
- Feekood开发环境介绍(2)-- 资源管理界面
- linux shell 远程执行命令
- CodeForces 148E Porcelain
- 1600 - Patrol Robot
- 使用 scp命令免登陆
- github上好用的第三方库
- ubuntu下安装lamp环境
- HTML Attributes
- 10410 - Tree Reconstruction
- 将文字转换为拼音
- CentOS 安装 openoffice 和swftools 编译安装