hdu 4968 Improving the GPA(dp)
来源:互联网 发布:熊猫看书软件 编辑:程序博客网 时间:2024/06/05 05:36
题目链接:hdu 4968 Improving the GPA
题目大意:给定平均分和科目数量,要求保证及格的前提下,求平均绩点的最大值和最小值。
解题思路:官方题解是暴力枚举,我的做法是dp。dp[i][j]表示i个科目,总分j(扣掉基础60分,减少复杂度)的情况,然后预处理出dp数组之后答案是通用的。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int maxn = 10;const int maxm = 400;const double INF = 0x3f3f3f3f;double l[maxn+5][maxm+5], r[maxn+5][maxm+5];inline double cal (int k) { if (k < 10) return 2.0; else if (k < 15) return 2.5; else if (k < 20) return 3.0; else if (k < 25) return 3.5; else return 4.0;}void init () { for (int i = 0; i <= maxn; i++) { for (int j = 0; j <= maxm; j++) { l[i][j] = 50; r[i][j] = 0; } } l[0][0] = r[0][0] = 0; for (int i = 0; i < maxn; i++) { for (int j = 0; j <= maxm; j++) { for (int k = 0; k <= 40; k++) { if (j + k > maxm) break; l[i+1][j+k] = min(l[i+1][j+k], l[i][j] + cal(k)); r[i+1][j+k] = max(r[i+1][j+k], r[i][j] + cal(k)); } } }}int main () { init(); int cas; scanf("%d", &cas); while (cas--) { int score, n; scanf("%d%d", &score, &n); score = (score - 60) * n; printf("%.4lf %.4lf\n", l[n][score] / n, r[n][score] / n); } return 0;}
0 0
- HDU 4968 Improving the GPA(dp)
- hdu 4968 Improving the GPA(dp)
- hdu 4968 Improving the GPA (dp)
- HDU-4968 Improving the GPA (DP)
- HDU 4968 Improving the GPA
- hdu 4968 Improving the GPA
- hdu 4968 Improving the GPA
- HDU 4968 Improving the GPA 模拟
- 【瞎搞】HDU 4968 Improving the GPA
- HDU 4968 Improving the GPA【数学】【暴力】
- HDU-4968 Improving the GPA 暴力枚举
- HDU 4968 Improving the GPA 贪心
- HDU4968:Improving the GPA(DP)
- HDOJ 4968 Improving the GPA
- 【HDOJ 4968】 Improving the GPA
- HDU 4968 Improving the GPA 多校第九场1009
- hdu 4968 Improving the GPA(暴力枚举)
- HDU 4968 Improving the GPA——暴力
- POJ-2724-Purifying Machine
- sql语句的使用
- 今天的问题
- Javascript模块化编程(一):模块的写法
- 学习视频
- hdu 4968 Improving the GPA(dp)
- nyoj 12 喷水装置(二)【贪心】+【区间完全覆盖覆盖】
- msdn之dll
- Visual Studio (2010)上手
- 指针作为函数的参数
- javascript基础
- MFC编程集锦
- 单播,组播和广播
- poj 2773 Happy 2006(数论:欧拉函数)