经典状压DP. f[i][j][k]=sum(f[i-1][j-cnt[k]][k]); cnt[i]放置情况为i时的国王数量 前I行放置情况为k时国王数量为J #include <iostream> #include <cstdio> using namespace std; #define N 1<<9 long long ans; int n,m; int ok_1[N],cnt[N]; int ok_2[N][N]; ][*+][N]; void init()…
有的DP题,某一部分的状态只有两种,选或不选. 开数组记录,代价太大,转移不方便. 状态压缩意为,用 “0/1“ 表示 “选/不选“ . 把状态表示为二进制整数. There are 10 kinds of people in the world, who knows binary and who doesn't. 用位运算判断条件并转移状态. hdu 6149 Valley Numer II 题目传送门 用f[i][j]表示选到前i个点,状态为j的答案. 枚举其他两个高点. 转移之前判断之前是…
Problem K. Kitchen Robot Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100610 Description Robots are becoming more and more popular. They are used nowadays not only in manufacturing plants, but also at home. One programmer wit…