链接:https://ac.nowcoder.com/acm/contest/1081/F
来源:牛客网

题目描述

The cows are playing that cool Japanese 'pinball' game called Pachinko. You've probably seen it, you drop a ball in the top and it hits nails on the way down, veering just a little left or right, until the ball comes out the bottom.
This pachinko game is special: the ball always hits the top nail of the R rows of nails (1 <= R <= 25) and then will hit either the right or left nail underneath that. From there, the ball can hit the next nail that's just a bit lower and to the left or right of the second nail, and so on. The ball never veers too far (i.e., more than 1/2 nail away) from the nail it just hit.
This game also has scoring that's unique: you get points XijX_{ij}Xij​ (0 <= XijX_{ij}Xij​ <= 3,000) for each little nail you hit on the way down. The cows want to maximize their score on this machine. What is the best score they can achieve?

Here's an example triangle and a good route:7                        *73   8                    *3   88   1   0                *8   1   02   7   4   4             2  *7   4   44   5   2   6   5         4  *5   2   6   5In the sample above, the route from 7 to 3 to 8 to 7 to 5 produces the highest sum: 30. It's not possible to go from 7 to 8 to 8 -- the 8 on the third row is too far away.

输入描述:

* Line 1: A single integer: R
* Lines 2..R+1: Line i+1 contains i space-separated integers that compose the scores of row R of the pachinko machine: Xi1,Xi2,...X_{i1},X_{i2}, ...Xi1​,Xi2​,...

输出描述:

* Line 1: A single integer that is the maximum achievable score.

示例1

输入

复制

5
7
3 8
8 1 0
2 7 4 4
4 5 2 6 5

输出

复制

30

说明

No other achievable sum is higher.

思路:深搜(dfs),搜索出一条路径元素和最大的路径,记录其路径元素之和

代码:

#include <iostream>
#include <bits/stdc++.h>using namespace std;int num[26][26], r, ans = 0, mx = 0;    //ans当前路径上元素之和,mx为当前所有路径上元素之和的最大值
bool book[26][26];
//int sl[26];               //记录路径
int next1[2]={0,1};void dfs(int x, int y)
{if(x == r){mx = max(mx, ans);
//        查案路径
//        for(int i = 1; i < r; i++)
//            printf("%d ", sl[i]);
//        printf("\n");}for(int i = 0; i < 2; i++){int tx = x + 1;         //只能下方和左下方的钉子int ty = y + next1[i];if(book[tx][ty] == 0 && tx <= r && ty <= r){book[tx][ty] = 1;ans += num[tx][ty];
//            sl[tx] = num[tx][ty];dfs(tx, ty);ans -= num[tx][ty];book[tx][ty] = 0;}}}int main()
{scanf("%d", &r);for(int i =0; i < r; i++){for(int j = 0; j <= i; j++)scanf("%d", &num[i][j]);}dfs(0, 0);printf("%d\n", mx + num[0][0]);return 0;
}

Cow Pinball相关推荐

  1. POJ 3268 D-Silver Cow Party

    http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  2. usaco Cow Tours 牛的旅行

    Cow Tours 牛的旅行 农民 John 的农场里有很多牧区.有的路径连接一些特定的牧区.一片所有连通的牧区称为一个牧场. 但是就目前而言,你能看到至少有两个牧区不连通.这样,农民 John 就有 ...

  3. 贪心  POJ - 3617 ​​​​​​​Best Cow Line

    Best Cow Line POJ - 3617 FJ is about to take his N (1 ≤ N ≤ 2,000) cows to the annual"Farmer of ...

  4. 【POJ】3268 Silver Cow Party (将有向图的边反转)

    问题链接:http://poj.org/problem?id=3268 [问题描述] One cow from each of N farms (1 ≤ N ≤ 1000) conveniently ...

  5. 解题报告:CF1307D Cow and Fields(最短路、最优解不等式化简)

    CF1307D Cow and Fields 整张无向图的边权为1. 首先求出 1,n1,n1,n 两个点的单源最短路径.这 kkk 个特殊点中,我们令第 aaa 个特殊点到 111 的距离为 xax ...

  6. SP11469 SUBSET - Balanced Cow Subsets(折半搜索+状态压缩)难度⭐⭐⭐⭐★

    题目链接 SP11469 SUBSET - Balanced Cow Subsets 题目翻译 给出N(1≤N≤20)N(1≤N≤20)N(1≤N≤20)个数M(i)(1<=M(i)<=1 ...

  7. P2888 [USACO07NOV]牛栏Cow Hurdles(Floyd算法)

    P2888 [USACO07NOV]牛栏Cow Hurdles 行 1-T: 行 i 为一个整数,表示任务i路径上最高的栏的高度的最小值.如果无法到达,输出 -1. 5 6 3 1 2 12 3 2 ...

  8. P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(加强版)(贪心+hash哈希)

    P2870 [USACO07DEC]最佳牛线,黄金Best Cow Line, Gold(加强版)(贪心+hash哈希) 洛谷上这道水题丧心病狂地把数据范围加到了500000 普通的做法肯定A不了了, ...

  9. H - Cow Contest POJ - 3660(Floyd 传递闭包)

    H - Cow Contest POJ - 3660 题意: 有 n 头牛比赛,边 1 -> 2 代表 1 能赢 2 ,给你 m 条边,问能确定出多少头牛的名次? 思路: 如果 1->2 ...

最新文章

  1. Debugging JTAG
  2. ap的ht模式_AP6256 STA模式操作示例
  3. CNN应用之基于R-CNN的物体检测-CVPR 2014-未完待续
  4. buck电路matlab,buck变换器介绍_buck变换器matlab仿真
  5. axure实现复选框全选_AxureRP8实战手册-案例73(全选与取消全选效果)
  6. spring boot 三种入参
  7. ios7自定义返回按钮后,右滑返回功能失效解决方法
  8. 调查了9648位Go用户:吐槽最多的竟是官方文档!
  9. k3c最新官改非常稳定了_软件聚分享库APP最新版下载-软件聚分享库v1.0.0安卓版下载...
  10. 【Linux】Linux系统学习
  11. 计算机音乐制作课程标准,苏少版《音乐课程标准》教材编写情况及基本思路
  12. 37 | 个人成长:学习安全,哪些资源我必须要知道?
  13. LoadRunner牛刀小试
  14. 写全武汉的火锅店..更新版 恩..欢迎补充 ^_^
  15. MacBook使用与应用推荐
  16. 微信公众号获取的实时坐标和高德地图坐标系的转换
  17. hand_mysql
  18. 数据库系统原理(一)引言
  19. Mac 使用 之 Permission denied XXX
  20. imu matlab,IMU姿态解算matlab

热门文章

  1. 【转】Awesome Python中文版来啦!
  2. str[]与*str的区别
  3. Scalers:持续行动至少要以年为单位
  4. Windows 10下视频播放器泛黄,颜色太暖、太亮
  5. Apple公司的官方声明
  6. 【历史】- UNIX发展史(BSD,GNU,linux)
  7. 《阿里巴巴 Android 开发手册》(一)
  8. Redis 秒杀案例
  9. java代码---------陈勇老师的
  10. 小白网工成长笔记之OSPF(1)