zoj 3211 Dream City 动态规划
2011-11-05 18:17
375 查看
原题连接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3211
这个是我看到的很经典的动态规划问题,状态转移很经典啊
解题思路: 一颗斜率(b)小的树,如果这次不用,那么他再也不会用到了。我是这么理解的……这样的话,就产生了一个顺序,也就是可以dp的顺序
我表达的不好,如果还是不懂,看代码吧,看完了就懂了
个人感觉很经典,至少状态很难想
这个是我看到的很经典的动态规划问题,状态转移很经典啊
解题思路: 一颗斜率(b)小的树,如果这次不用,那么他再也不会用到了。我是这么理解的……这样的话,就产生了一个顺序,也就是可以dp的顺序
我表达的不好,如果还是不懂,看代码吧,看完了就懂了
个人感觉很经典,至少状态很难想
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> using namespace std; int n,m; struct note { int a,b; }tree[300]; int dp[300][300]; bool cmp(const note a,const note b) { return a.b < b.b; } int main() { int t; cin >> t; while(t--) { cin >> n >> m; for(int i = 1;i <= n;i++) cin >> tree[i].a; for(int i = 1;i <= n;i++) cin >> tree[i].b; sort(tree+1,tree+n+1,cmp); //cout << tree[0].b << tree[1].b; memset(dp,0,sizeof(dp)); for(int i = 1;i <= n;i++) { for(int j = 1;j <= m;j++) { dp[i][j] = max(dp[i-1][j],dp[i-1][j-1] + tree[i].a + tree[i].b*(j-1)); } } cout << dp [m] << "\n"; } return 0; }
相关文章推荐
- zoj 3211 Dream City(DP)
- zoj 3211 dream city 贪心 dp和记忆化搜索
- ZOJ 3211 Dream City(dp)
- ZOJ 3211 Dream City (J) DP
- zoj 3211 - Dream City
- ZOJ 3211 Dream City(线性DP)
- ZOJ 3211 Dream City DP 01背包 经典问题
- ZOJ-3211-Dream City-DP背包问题+贪心
- ZOJ 3211 Dream City
- ZOJ 3211 Dream City
- zoj 3211 Dream City
- zoj 3211 - Dream City
- ZOJ 3211 Dream City(DP)
- ZOJ3206 Disaster Area Reconstruction ZOJ 3211 Dream City ZOJ 3212 K-Nice
- ZOJ-3211-Dream City【6th浙江省赛】【dp】
- ZOJ 3211 6th省赛 J Dream City【DP】
- zoj 3211 Dream City 贪心+动规
- ZOJ - 3211 Dream City
- ZOJ 3211 Dream City(DP)
- Dream City ZOJ - 3211 (动态规划)