HDU 1712 ACboy needs your help DP
2015-12-22 19:27
337 查看
题意:有n门课程,m天,给一个矩阵,矩阵每个元素AijA_{ij}花jj天学习ii课程可以得到的价值。
思路:DP:now[ia]=max(now[ia],pre[ia−j]+A[i][j])now[ia] = max(now[ia],pre[ia-j]+A[i][j]),因为Ai1,Ai2,…,AimA_{i1},A_{i2},\ldots,A_{im}是相关的,所以要用一个pre数组来存上一门课程处理过后的状态。
http://acm.hdu.edu.cn/showproblem.php?pid=1712/********************************************* Problem : HDU 1712 Author : NMfloat InkTime (c) NM . All Rights Reserved . ********************************************/ #include <map> #include <set> #include <queue> #include <stack> #include <cmath> #include <ctime> #include <cstdio> #include <cstring> #include <cstdlib> #include <iostream> #include <algorithm> #define rep(i,a,b) for(int i = (a) ; i <= (b) ; i ++) #define rrep(i,a,b) for(int i = (b) ; i >= (a) ; i --) #define repE(p,u) for(Edge * p = G[u].first ; p ; p = p -> next) #define cls(a,x) memset(a,x,sizeof(a)) #define eps 1e-8 using namespace std; const int MOD = 1e9+7; const int INF = 0x3f3f3f3f; const int MAXN = 1e5+5; const int MAXE = 2e5+5; typedef long long LL; typedef unsigned long long ULL; int T,n,m,k; int fx[] = {0,1,-1,0,0}; int fy[] = {0,0,0,-1,1}; int A[105][105]; int pre[105]; int now[105]; void input() { rep(i,1,n) rep(j,1,m) scanf("%d",&A[i][j]); } void solve() { cls(now,0); cls(pre,0); rep(i,1,n) { rep(j,1,m) { rrep(ia,j,m) { now[ia] = max(now[ia],pre[ia-j]+A[i][j]); } } rep(j,1,m) { pre[j] = now[j];} //puts(""); } int ans = 0; rep(i,1,m) { ans = max(ans,now[i]); } printf("%d\n",ans); } int main(void) { //freopen("a.in","r",stdin); while(scanf("%d %d",&n,&m),n+m) { input(); solve(); } return 0; }
相关文章推荐
- VMware装Win7
- WebSocket的JavaScript例子
- hexo github
- BZOJ 1008: [HNOI2008]越狱 快速幂
- Perl6 -1.1 数据类型
- 《需求分析和系统设计》读书笔记二
- n-armed bandit notes_e-greedy
- Java多线程总结(8)concurrent.locks包下的锁机制的使用
- webService学习五(插入片,---监控方法)
- leetcode -- Sudoku Solver -- 经典重点
- Bootstrap输入建议库 autosuggest.js
- POJ1390Blocks(DP+好题+抽空再来理解理解)
- 蓝懿iOS编写小游戏实现新功能
- ListView被嵌套在ScrollView里面
- iOS动态图实现(1)
- RelativeLayout常用属性介绍
- scala-46: ClassTag 、Manifest、ClassManifest、TypeTag代码实战及其在Spark中的应用源码解析
- http://www.ibm.com/developerworks/cn/opensource/os-cn-cas/
- 2007: [Noi2010]海拔
- Test checkout of feature 'Compiler' failed.