poj 1018 DP
2013-11-05 22:45
281 查看
AC代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int dp[101][10001]; int main(){ int T, N; int bandwidth[101], price[101]; int number, max_band; cin >> T; while( T-- ){ cin >> N; memset( dp, -1, sizeof( dp ) ); max_band = 0; for( int i = 1; i <= N; i++ ){ cin >> number; for( int im = 0; im < number; im++ ){ cin >> bandwidth[im] >> price[im]; max_band = max( bandwidth[im], max_band ); } if( i == 1 ){ dp[i-1][max_band] = 0; } for( int j = 1; j <= max_band; j++ ){ if( dp[i-1][j] == -1 ){ continue; } for( int k = 0; k < number; k++ ){ int temp = min( bandwidth[k], j ); if( dp[i][temp] != -1 ){ dp[i][temp] = min( dp[i][temp], dp[i-1][j] + price[k] ); }else{ dp[i][temp] = dp[i-1][j] + price[k]; } } } } double ans = 0; for( int i = max_band; i >= 1; i-- ){ if( dp [i] != -1 ){ double temp = 1.0 * i / dp [i]; // if (temp > ans) { // ans = temp; // } ans = max( ans, temp ); } } printf( "%.3lf\n", ans ); } return 0; }
相关文章推荐
- POJ 1018 dp问题的一般过程
- POJ 1018 Communication System DP
- POJ 1018 Communication System(分组背包DP)
- poj 1018 Communication System (dp | 贪心)
- poj 1018(dp)
- poj 1018 dp
- POJ 1018 Communication System(简单DP)
- POJ1018 DP 一道自己独立思考出的DP题目 兼 12月份算法学习小结[更新]
- POJ 1018 Communication System(DP+离散化)
- 【POJ 1018】Communication System(dp|贪心)
- poj 1018 Communication System(DP)
- poj 1018 dp
- poj 1018 Communication System(DP)
- poj - 1018 - Communication System(dp)
- POJ_1018_(dp)
- POJ 1018 Communication System(DP)
- POJ 1018 Communication System(树形DP)
- POJ-1018(DP)
- POJ 1018 Communication System dp
- POJ 1018 Communication System(二维DP)