Score Inflation
来源:互联网 发布:linux修改网络配置文件 编辑:程序博客网 时间:2024/05/09 23:20
题意:有N组试题,每组试题得分和所需时间分别为worth[i] 和 cost[i],一组试题可以选取多次,求M时间内能得到的最高分为多少?
解题思路:
- 典型的无界背包问题,用DP解决
- 详情参见http://zh.wikipedia.org/wiki/%E8%83%8C%E5%8C%85%E9%97%AE%E9%A2%98
代码:
/*ID: zc.rene1LANG: CPROG: inflate */#include<stdio.h>#include<stdlib.h>#include<string.h>int main(void){ FILE *fin, *fout; int M, N; int *worth, *cost, *result; int i, j, temp_max; fin = fopen("inflate.in", "r"); fout = fopen("inflate.out", "w"); fscanf(fin, "%d %d", &M, &N); worth = (int *)malloc(N*sizeof(int)); cost = (int *)malloc(N*sizeof(int)); for (i=0; i<N; i++) {fscanf(fin, "%d %d", &worth[i], &cost[i]); } result = (int *)malloc((M+1)*sizeof(int)); memset(result, 0, (M+1)*sizeof(int)); for (i=1; i<=M; i++) {temp_max = 0;for (j=0; j<N; j++){ if (cost[j] <= i) {if ((worth[j] + result[i - cost[j]]) > temp_max){ temp_max = (worth[j] + result[i - cost[j]]);} }}result[i] = (result[i-1] > temp_max)? result[i-1] : temp_max; } fprintf(fout, "%d\n", result[M]); return 0;}
- Score Inflation
- USACO 3.1 Score Inflation
- usaco Score Inflation
- usaco Score Inflation
- USACO:Score Inflation
- USACO-Score Inflation
- usaco Score Inflation
- usaco3.1.1 Score Inflation
- Score Inflation 总分
- USACO Score Inflation 总分
- USACO 3.1 Score Inflation (完全背包) P2722 总分 Score Inflation
- 【动态规划】【USACO】Score Inflation
- USACO:Score Inflation解题报告
- 【完全背包】Score Inflation 总分
- USACO 3.1.2 Score Inflation
- USACO 3.1 Score Inflation (inflate)
- USACO3.1.2 Score Inflation (inflate)
- USACO3.1.2 Score Inflation (inflate)
- python with as 使用
- 黑马程序员-----Java中类的初始化
- Eclipse导入Android项目的正确方法
- UNITY3D物理引擎Rigidbody,Collider,PhysicMaterial的整理
- ORACLE 分页效率比较
- Score Inflation
- Ant 基础
- [剑指offer][面试题26]复杂链表的复制
- Android 广播静态,动态示例(简洁新手专用)
- Unity3D界面插件NGUI核心组件说明
- Flex 与 java交互的方法
- OCP-1Z0-051-V9.02-46题
- iOS - 简单录音:
- 算法导论学习笔记(1)