A1148 | [COCI-2008_2009-contest1]#5 SKAKAVAC
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
A grasshopper is in a flower field. The field contains N·N flowers arranged in N rows and N columns.
For each flower in the field, we know how many petals it has.
The grasshopper is initially on the flower in row R and column C. Its goal is to visit as many flowers as possible while obeying these rules:
1. It can only jump into an adjacent row or column. If it jumps into the adjacent row, it must jump at least two columns, and if it jumps into the adjacent column, it must jump at least two rows.
In other words, it can jump from flower (r1, c1) to flower (r2, c2) if:
• |r1-r2| = 1 and |c1-c2|> 1 or
• |c1-c2| = 1 and |r1-r2|> 1
2. The number of petals on the next flower must be strictly larger than the number of petals on the previous flower.
Write a program that calculates the largest number of flowers the grasshopper can visit.
For each flower in the field, we know how many petals it has.
The grasshopper is initially on the flower in row R and column C. Its goal is to visit as many flowers as possible while obeying these rules:
1. It can only jump into an adjacent row or column. If it jumps into the adjacent row, it must jump at least two columns, and if it jumps into the adjacent column, it must jump at least two rows.
In other words, it can jump from flower (r1, c1) to flower (r2, c2) if:
• |r1-r2| = 1 and |c1-c2|> 1 or
• |c1-c2| = 1 and |r1-r2|> 1
2. The number of petals on the next flower must be strictly larger than the number of petals on the previous flower.
Write a program that calculates the largest number of flowers the grasshopper can visit.
输入格式
The first line contains the integer N (1 ≤ N ≤ 1500), the size of the field.
The second line contains integers R (1 ≤ R ≤ N) and C (1 ≤ C ≤ N), the grasshopper's initial position.
The next N lines contain N positive integers separated by spaces, each less than 1 000 000, the numbers of petals on the flowers.
The second line contains integers R (1 ≤ R ≤ N) and C (1 ≤ C ≤ N), the grasshopper's initial position.
The next N lines contain N positive integers separated by spaces, each less than 1 000 000, the numbers of petals on the flowers.
输出格式
Output a single integer – the largest number of flowers the grasshopper can visit.
输入输出样例
输入 #1
4 1 1 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7
输出 #1
4
输入 #2
5 3 3 20 16 25 17 12 11 13 13 30 17 15 29 10 26 11 27 19 14 24 22 23 21 28 18 13
输出 #2
21
In test data worth 50% of points, N will be at most 100.
In test data worth 80% of points, N will be at most 1000.
In test data worth 80% of points, N will be at most 1000.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted