zoj3211 按增长量排序 然后dp
来源:互联网 发布:卓诗尼官方旗舰店淘宝 编辑:程序博客网 时间:2024/05/22 15:51
将自己历史的AC共享
zoj3211 DP题
按增长量排序,然后dp,dp[i][j]=max(dp[i-1][k]+a[i]+(i-1)*b[j]),其实有O(mn)的dp
//1882141 2009-05-23 22:11:52 Accepted 3211 C++ 810 448 green tea #include <cstdlib>#include <cctype>#include <cstring>#include <cstdio>#include <cmath>#include <algorithm>#include <vector>#include <string>#include <iostream>#include <sstream>#include <map>#include <set>#include <queue>#include <stack>#include <fstream>#include <numeric>#include <iomanip>#include <bitset>#include <list>#include <ctime>#include <utility>using namespace std;#define inf (1<<30)#define PB push_back#define mset(x,a) memset(x,(a),sizeof(x))#define SIZE(X) ((int)X.size())typedef vector<int> VI;typedef vector<char> VC;typedef vector<string> VS;typedef long long LL;typedef unsigned long long uLL;#define twoL(X) (((LL)(1))<<(X))const double PI=acos(-1.0);const double eps=1e-11;template <class T> T sqr(T x) {return x*x;}template <class T> T gcd(T a, T b) {if(a<0) return (gcd(-a,b)); if(b<0) return (gcd(a,-b)); return (b==0)?a:gcd(b,a%b);}template <class T> T lcm(T a, T b) {return a*b/gcd(a,b);}LL toLL(string s) { istringstream sin(s); LL t; sin>>t; return t;}int toInt(string s) {istringstream sin(s); int t; sin>>t; return t;}string toString(LL v) {ostringstream sout; sout<<v; return sout.str();}string toString(int v) {ostringstream sout; sout<<v; return sout.str();}#define FOREACH(it, a) for(typeof((a).begin()) it = (a).begin(); it!=(a).end(); ++it)#define ALL(x) ((x).begin, (x).end())#define cross(a, b, c) ((c).x-(a).x)*((b).y-(a).y)-((b).x-(a).x)*((c).y-(a).y)#define sq_dist(p, q) ((p).x-(q).x)*((p).x-(q).x)+((p).y-(q).y)*((p).y-(q).y)int T;struct point { int w, add;};point a[260];bool cmp(point p1, point p2) { return p1.add < p2.add;}int dp[260][260];//dp[i][j]´ú±íÇ°iÌìÒÔj½áβµÄ×î´óÖµint main(){ int n, m; scanf("%d", &T); while ( T-- ) { scanf("%d%d", &n, &m); for ( int i = 1; i <= n; ++i ) scanf("%d", &a[i].w); for ( int i = 1; i <= n; ++i ) scanf("%d", &a[i].add); sort(a+1, a+n+1, cmp); mset(dp, 0); for ( int i = 1; i <= n; ++i ) dp[1][i] = a[i].w; for ( int i = 2; i <= m; ++i ) for ( int j = i; j <= n; ++j ) for ( int k = i-1; k < j; ++k ) dp[i][j] = max(dp[i][j], dp[i-1][k]+a[j].w+(i-1)*a[j].add); int ans = 0; for ( int i = 1; i <= n; ++i ) ans = max(ans, dp[m][i]); printf("%d\n", ans); } return 0;}
如觉得还有问题 可参考其他相关文章
zoj3211 其他1
zoj3211 其他2
zoj3211 其他3
zoj3211 其他4
zoj3211 其他5
zoj3211 其他6
0 0
- zoj3211 按增长量排序 然后dp
- zoj3211(贪心+dp)
- 按点击量排序
- 取得自动增长量(MSSQL)
- 查看ORACLE Archive log增长量
- 发明专利申请量同比增长160%
- 数字排序,波动增长
- ZOJ3211 Dream City
- ZOJ3211--Dream City
- ZOJ3211-Dream City
- 90-100的排在前面,然后按id排序
- 匹配量排序
- 时间和数量排序
- DataTable排序.然后进行GroupBY
- linux_shell读文件,然后排序
- awk 先按行相减,然后排序输出
- 依靠dba_hist_tbspc_space_usage视图 获得表空间的每日增长量
- 统计数据库每天的数据增长量的脚本
- [数据结构]队列的基本操作
- 剑指offer1 二维数组中的查找
- Linux学习 - Ubuntu 14.04配置Opencv环境
- 面向对象 eat
- myeclipse中SVN插件安装遇到的问题:Failed to load JavaHL Library
- zoj3211 按增长量排序 然后dp
- NoSQL之Redis学习笔记(一)
- 读书笔记--Android布局和UI组件中的布局管理器
- IOS图层Layer学习笔记(三)—— CALayer(下)
- A.挑战密室
- Xshell是什么
- TextView设置android:ellipsize=marquee不滚动
- 共享内存与线程局部存储
- jquery的插件写法