暑期个人赛--第二场--B
来源:互联网 发布:南笙 知乎 编辑:程序博客网 时间:2024/06/05 03:49
B. 丁神又去谷歌 2014新生暑假个人排位赛02
时间限制 1000 ms 内存限制 65536 KB
题目描述
丁神又要去Google上班了,这一次丁神想多做几道水题,并使题目的总水量最大.丁神同一时刻只能在水一道题,只有做完这道题才能得到它的水值,丁神的总时间为
输入格式
输入第一行为数据组数
输出格式
对于每组数据,输出对应的最大总水量,每个输出占一行。
输入样例
110 28 166 12
输出样例
16
赛中提交:WA WA WA AC
题目大意:简单的背包DP
思路:
背包dp
WA原因和反省:
(1)dp数组的第二个下标开得太小,原来只开了106,而t(背包容量)的范围是1000
开成了1006就过了
(2)另外就是long long的问题,数据很大最大是1e10,因为还要一直加和,所以必须要开int
下面是AC代码
#include <iostream>#include <string.h>#include <stdio.h>#include <stdlib.h>#include <math.h>#include <string>#include <vector>#include <list>#include <map>#include <queue>#include <stack>#include <bitset>#include <algorithm>#include <numeric>#include <functional>#define maxn 100005 using namespace std;typedef long long ll; int v[106],w[106];ll dp[106][1006]; int main(){ int T; scanf("%d",&T); while(T--){ int n,t; memset(dp,0,sizeof(dp)); scanf("%d %d",&t,&n); for(int i=0;i<n;i+=1){ scanf("%d %d",&w[i],&v[i]); } for(int i=0;i<n;i+=1){ for(int j=0;j<=t;j+=1){ if(j<w[i]){ dp[i+1][j]=dp[i][j]; } else{ dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]); } } } printf("%lld\n",dp[n][t]); } return 0;}
0 0
- 暑期个人赛--第二场--B
- 暑期个人赛第二场
- 暑期个人赛--第二场--A
- 暑期个人赛--第二场--D
- 暑期个人赛--第二场--C
- 暑期个人赛--第三场--B
- 暑期个人赛--第四场--B
- 暑期个人赛--第一场--B
- 暑期个人赛--第五场--B
- 暑期个人赛--第七场--B
- 暑期个人赛--第二场--D--every SG(重)
- 暑期个人赛--第六场--B(常复习~!!!)
- 暑期个人赛第一场
- 暑期个人赛--第八场--B(关于手写队列的启示+题目有坑)
- (待切,标记上)暑期个人赛--第九场--B
- 暑期个人赛--第三场--A
- 暑期个人赛--第三场--C
- 暑期个人赛--第一场--E
- 算法-欧几里得算法(C++实现)
- IOS添加小图标
- 编程名言
- - Fractal(3.4.1)
- poj 3253Fence Repair
- 暑期个人赛--第二场--B
- VC++笔记十
- do{...}while(0)的意义和用法
- 54 小明的存钱计划
- OpenCV的cvResize函数——图像缩放
- Linux MySQL的使用
- destructor(析构函数)
- Jbpm4.4 使用
- Python 正则表达式限定文本长度