# Codevs 1358 棋盘游戏

Codevs 1358棋盘游戏

## 样例1

### 样例输入1[复制]



0 1 2 3 4 5 6 7 8 9

1 1 1 1 1 1 1 1 1 0

2 1 1 1 1 1 1 1 1 0

3 1 1 1 1 1 1 1 1 0

4 1 1 1 1 1 1 1 1 0

5 1 1 1 1 1 1 1 1 0

6 1 1 1 1 1 1 1 1 0

7 1 1 1 1 1 1 1 1 0

8 1 1 1 1 1 1 1 1 0

9 1 1 1 1 1 1 1 1 5



### 样例输出1[复制]

50

## 来源

CodeVS 1358

用(0~2^10-1)来表示状态

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define pi acos(-1.0)
#define maxn (10 + 1)
#define mol 1000000007
#define inf 50000
#define Lowbit(x) (x & (-x))
using namespace std;
typedef long long int LLI;

int dp[maxn][maxn][1 << maxn];
int a[maxn][maxn];

int main() {
//    freopen("in.txt","r",stdin);
//    freopen("out.txt","w",stdout);
for(int i = 1; i <= 10; i ++)
for(int j = 1; j <= 10; j ++)
scanf("%d",&a[i][j]);
for(int i = 1;i <= 10;i ++){
for(int j = 1;j <= 10;j ++){
for(int k = 0;k < (1 << 10);k ++){
dp[i][j][k] =  inf;
if(k & (1 << a[i][j])){
if(i > 1)   dp[i][j][k] = a[i][j] + min(dp[i - 1][j][k - (1 << a[i][j])],dp[i - 1][j][k]);
if(j > 1)   dp[i][j][k] = min(dp[i][j][k],a[i][j] + min(dp[i][j - 1][k - (1 << a[i][j])],dp[i][j - 1][k]));
}
}
if(i == 1 && j == 1)    dp[i][j][1 << a[i][j]] = a[i][j];
}
}
printf("%d\n",dp[10][10][(1 << 10) - 1]);
return 0;
}


03-27 414

12-17 521

02-17 90

08-17 2068

02-03 443

07-06 282

05-26 272

03-17 441

02-28 1442

04-01 1109