杭电OJ 1355:The Peanuts
来源:互联网 发布:8080端口的作用 编辑:程序博客网 时间:2024/05/18 02:52
杭电上将题目分到了DP,但是好像直接用贪心算法就可以做出来,不知道是不是数据不够强。
C++代码:
#include<stdio.h>#include<algorithm>#include<math.h>using namespace std;struct peanut{int x,y,c;}arr[5000];bool cmp(peanut a,peanut b){return a.c>b.c;}int main(){//freopen("1.txt","r",stdin);int xx,yy,maxt,w,q,t,ss,sum,i,j;scanf("%d",&t);while(t--){scanf("%d%d%d",&xx,&yy,&maxt);for(w=i=1;i<=xx;i++){for(j=1;j<=yy;j++){scanf("%d",&q);arr[w].x=i;arr[w].y=j;arr[w++].c=q;}}sort(arr+1,arr+w,cmp);for(ss=sum=0,i=1;i<w;i++){if(i==1)sum+=arr[1].x;else sum+=abs(arr[i].x-arr[i-1].x)+abs(arr[i].y-arr[i-1].y);if(sum+arr[i].x<=maxt-1){ss+=arr[i].c;sum++;}elsebreak;}printf("%d\n",ss);}return 0;}
0 0
- 杭电OJ 1355:The Peanuts
- hdu 1355 The Peanuts
- hdu 1355 The Peanuts(DP)
- HDOJ 1355 The Peanuts(水)
- 杭电oj problem1071 the area
- 杭电oj-1115-Lifting the Stone
- 杭电OJ Let the Balloon Rise
- 杭电 OJ 1194 Beat the Spread!
- 杭电 OJ 1302 The Snail
- fjnu 1013 The Peanuts
- pku 1928 The Peanuts
- poj 1928 The Peanuts
- hdu1355 The Peanuts
- POJ-1928-The Peanuts
- POJ1928 The Peanuts
- POJ1928 The Peanuts
- POJ 1928 The Peanuts
- POJ 1928 The Peanuts
- 使用 Interface Builder 兼容 iOS6 和iOS7
- 博客2013年度数据统计和排行
- android源码里那些常用的Utils工具类
- LLVM(三):Tablegen简介
- 求出栈序列,二叉树,二叉搜索树的计数问题
- 杭电OJ 1355:The Peanuts
- Oracle 同义词
- 2014年3月4号CSDN博客签到帖
- C++矩阵运算库推荐
- oauth对接淘宝订单
- #ifndef#define#endif的用法(整理)
- 在Servlet中设置参数小实验
- 啊哈!算法——排序算法总结:小哼买书
- 无线网络加密技术总结