多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > CodeForces 148E Porcelain dp+背包(水

CodeForces 148E Porcelain dp+背包(水

來源:程序員人生   發布時間:2015-04-07 08:17:13 閱讀次數:2758次

題目鏈接:點擊打開鏈接

題意:

給定1個n層書架,1共取m本書。

下面n行給出每層書的價值。

每次可以取任意1層的最左端或最右真個1本書。

問能取得的最大價值。

思路:

1、明顯是先求出對每層任取任意本書能取得的最大價值。

2、然后背包1下。

1:

對1層書任意j本,那末1定是從左端取k本,右端取 j-k本,求個前綴和然后枚舉 j和k便可。每層n^2的dp

2:

分組背包。

import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.text.DecimalFormat; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Deque; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.Map; import java.util.PriorityQueue; import java.util.Scanner; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Queue; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; public class Main { int m, n; int[] sum = new int[N], num = new int[N]; int[][] dp = new int[N][N], h = new int[2][M]; void work() throws Exception{ n = Int(); m = Int(); for(int i = 1; i <= n; i++){ num[i] = Int(); sum[0] = 0; for(int j = 1; j <= num[i]; j++){ sum[j] = sum[j⑴]+Int(); } dp[i][0] = 0; for(int j = 1; j <= num[i]; j++){ dp[i][j] = 0; for(int k = 0; k <= j; k++) dp[i][j] = max(dp[i][j], sum[k] + sum[num[i]] - sum[num[i]-j+k]); } } int cur = 0, old = 1; for(int i = 0; i <= m; i++)h[cur][i] = 0; for(int i = 1; i <= n; i++) { cur ^= 1; old ^= 1; for(int j = 0; j <= m; j++)h[cur][j] = h[old][j]; for(int j = 0; j <= num[i]; j++) { for(int k = j; k <= m; k++) h[cur][k] = max(h[cur][k], h[old][k-j]+dp[i][j]); } } out.println(h[cur][m]); } public static void main(String[] args) throws Exception{ Main wo = new Main(); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); // in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); // out = new PrintWriter(new File("output.txt")); wo.work(); out.close(); } static int N = 101; static int M = 10001; DecimalFormat df=new DecimalFormat("0.0000"); static int inf = (int)1e9; static long inf64 = (long) 1e18; static double eps = 1e⑻; static double Pi = Math.PI; static int mod = (int)1e9 + 7 ; private String Next() throws Exception{ while (str == null || !str.hasMoreElements()) str = new StringTokenizer(in.readLine()); return str.nextToken(); } private int Int() throws Exception{ return Integer.parseInt(Next()); } private long Long() throws Exception{ return Long.parseLong(Next()); } private double Double() throws Exception{ return Double.parseDouble(Next()); } StringTokenizer str; static Scanner cin = new Scanner(System.in); static BufferedReader in; static PrintWriter out; /* class Edge{ int from, to, dis, nex; Edge(){} Edge(int from, int to, int dis, int nex){ this.from = from; this.to = to; this.dis = dis; this.nex = nex; } } Edge[] edge = new Edge[M<<1]; int[] head = new int[N]; int edgenum; void init_edge(){for(int i = 0; i < N; i++)head[i] = ⑴; edgenum = 0;} void add(int u, int v, int dis){ edge[edgenum] = new Edge(u, v, dis, head[u]); head[u] = edgenum++; }/**/ int upper_bound(int[] A, int l, int r, int val) {// upper_bound(A+l,A+r,val)-A; int pos = r; r--; while (l <= r) { int mid = (l + r) >> 1; if (A[mid] <= val) { l = mid + 1; } else { pos = mid; r = mid - 1; } } return pos; } int Pow(int x, int y) { int ans = 1; while (y > 0) { if ((y & 1) > 0) ans *= x; y >>= 1; x = x * x; } return ans; } double Pow(double x, int y) { double ans = 1; while (y > 0) { if ((y & 1) > 0) ans *= x; y >>= 1; x = x * x; } return ans; } int Pow_Mod(int x, int y, int mod) { int ans = 1; while (y > 0) { if ((y & 1) > 0) ans *= x; ans %= mod; y >>= 1; x = x * x; x %= mod; } return ans; } long Pow(long x, long y) { long ans = 1; while (y > 0) { if ((y & 1) > 0) ans *= x; y >>= 1; x = x * x; } return ans; } long Pow_Mod(long x, long y, long mod) { long ans = 1; while (y > 0) { if ((y & 1) > 0) ans *= x; ans %= mod; y >>= 1; x = x * x; x %= mod; } return ans; } int gcd(int x, int y){ if(x>y){int tmp = x; x = y; y = tmp;} while(x>0){ y %= x; int tmp = x; x = y; y = tmp; } return y; } int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } double max(double x, double y) { return x > y ? x : y; } double min(double x, double y) { return x < y ? x : y; } long max(long x, long y) { return x > y ? x : y; } long min(long x, long y) { return x < y ? x : y; } int abs(int x) { return x > 0 ? x : -x; } double abs(double x) { return x > 0 ? x : -x; } long abs(long x) { return x > 0 ? x : -x; } boolean zero(double x) { return abs(x) < eps; } double sin(double x){return Math.sin(x);} double cos(double x){return Math.cos(x);} double tan(double x){return Math.tan(x);} double sqrt(double x){return Math.sqrt(x);} }



生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美日韩乱 | 欧美日韩大尺码免费专区 | 日韩欧美亚洲国产高清在线 | 久久受www免费人成看片 | 天天精品| 午夜美女影院 | 欧美色欧| 真人毛片免费全部播放完整 | 亚洲日产2021三区在线 | 两性午夜欧美高清做性 | 成人不卡在线 | 羞羞动漫视频在线观看 | 亚洲区在线播放 | 国产婷婷高清在线观看免费 | 欧美精品videosex性欧美 | 色综合久久中文 | 成人精品视频在线观看播放 | 免费色网址 | h在线视频 | 国产日韩欧美第一页 | 国产91区精品福利在线社区 | 美女啪啪免费网站 | 国产亚洲精品一区二区在线观看 | 尤物在线视频 | 亚洲国产亚洲片在线观看播放 | www.av在线.com | 手机看片久久高清国产日韩 | free欧美xxxxvideo free欧美性杂交hd | 欧美日韩加勒比一区二区三区 | 亚洲国产欧美在线成人aaaa | 欧美成人观看免费完全 | 高清一级毛片免免费看 | 日本一级α一片免费视频 | 欧美精品久久久久久久久大尺度 | 亚洲图片综合网 | 国产精品久久久久久一区二区三区 | 日本在线观看中文字幕 | 亚洲成人在线播放 | 国产a在亚洲线播放 | 国产一区二区不卡免费观在线 | 全亚洲最大的免费影院 |