Codeforces1332D. Walk on Matrix(构造/详解)

Description

Bob is playing a game named “Walk on Matrix”.

In this game, player is given an n×m matrix A=(ai,j), i.e. the element in the i-th row in the j-th column is ai,j. Initially, player is located at position (1,1) with score a1,1.

To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix.

However, each move changes player’s score to the bitwise AND of the current score and the value at the position he moves to.

Bob can’t wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem.
在这里插入图片描述

However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n×m matrix A=(ai,j) such that

1≤n,m≤500 (as Bob hates large matrix);
0≤ai,j≤3⋅105 for all 1≤i≤n,1≤j≤m (as Bob hates large numbers);
the difference between the maximum score he can get and the output of his algorithm is exactly k.
It can be shown that for any given integer k such that 0≤k≤105, there exists a matrix satisfying the above constraints.

Please help him with it!

Input

The only line of the input contains one single integer k (0≤k≤105).

Output

Output two integers n, m (1≤n,m≤500) in the first line, representing the size of the matrix.

Then output n lines with m integers in each line, ai,j in the (i+1)-th row, j-th column.

思路

Bob的dp会和最优解不同,那就考虑为什么会不同
把矩阵
3 2
1 1
用二进制显示就是
11 10

01 01
可以发现两条路径是不同的,然后考虑怎么让两条路径的差为k
因为与的的性质可以这样构造
111111(二进制) 100000(二进制)
k(十进制的k) k(十进制的k)
下面一条路是k,上面是0
最后就是如何让Bob的dp选择上面那一条路
可以在中间加一列
111111(二进制) 100000(二进制) 100000(二进制)
k(十进制的k) 111111(二进制) k(十进制的k)
Bob的dp就会贪心地选择路径
(1,1)(1,2)(1,3)(2,3)
或者路径
(1,1)(1,2)(2,2)(2,3)

#include <bits/stdc++.h>
using namespace std;
int main()
{
    //printf("%d\n",pow_(2,18)-1);
    int k;
    scanf("%d",&k);
    printf("2 3\n");
    printf("262143 131072 0\n");//262143=2^18-1   131072=2^17
    printf("%d 262143 %d\n",k,k);
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值