标签:enter iterator test 思维 back func 贪心 min --
题目意思好毒瘤
很容易想到 \(dp\) 状态
\(dp[i][j][k]\) 表示枚举到第 \(i\) 个位置,左大拇指在 \(j\),右大拇指在 \(k\) 的最少代价
对于每一个按键,直接枚举用哪个手去覆盖即可
但是题目那个手不能覆盖怎么处理?
其实并不需要考虑,这种情况一定会被一种同样优秀的方法替代掉
#include <map>
#include <set>
#include <ctime>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <string>
#include <numeric>
#include <cstring>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std ;
//#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define loop(s, v, it) for (s::iterator it = v.begin(); it != v.end(); it++)
#define cont(i, x) for (int i = head[x]; i; i = e[i].nxt)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define all(x) x.begin(), x.end()
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define iv inline void
#define enter cout << endl
#define siz(x) ((int)x.size())
#define file(x) freopen(#x".in", "r", stdin),freopen(#x".out", "w", stdout)
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair <int, int> pii ;
typedef vector <int> vi ;
typedef vector <pii> vii ;
typedef queue <int> qi ;
typedef queue <pii> qii ;
typedef set <int> si ;
typedef map <int, int> mii ;
typedef map <string, int> msi ;
const int N = 1010 ;
const int INF = 0x3f3f3f3f ;
const int iinf = 1 << 30 ;
const ll linf = 2e18 ;
const int MOD = 1000000007 ;
const double eps = 1e-7 ;
void print(int x) { cout << x << endl ; exit(0) ; }
void PRINT(string x) { cout << x << endl ; exit(0) ; }
void douout(double x){ printf("%lf\n", x + 0.0000000001) ; }
template <class T> void chmin(T &a, T b) { if (a > b) a = b ; }
template <class T> void chmax(T &a, T b) { if (a < b) a = b ; }
void upd(int &a, int b) { a = min(a, b) ; }
void mul(int &a, int b) { a = 1ll * a * b % MOD ; }
int l, r, n ;
int dp[N][60][60] ;
int a[N] ;
int calc(int s, int e) {
return floor(sqrt(fabs((double) (e - s)))) ;
}
signed main(){
// freopen("test.in", "r", stdin) ;
// freopen("test.out", "w", stdout) ;
while (scanf("%d%d%d", &l, &r, &n) != EOF) {
rep(i, 0, n - 1) scanf("%d", &a[i]) ;
rep(i, 0, 1009)
rep(j, 4, 59)
rep(k, 0, 59)
dp[i][j][k] = iinf ;
dp[0][l][r] = 0 ;
rep(i, 0, n - 1)
rep(j, 4, 51)
rep(k, 0, 47) {
if (dp[i][j][k] == iinf) continue ;
for (int l = a[i]; l <= 51 && l < a[i] + 9; l++) {
upd(dp[i + 1][l][k], dp[i][j][k] + calc(j, l)) ;
}
for (int l = a[i]; l >= 0 && l > a[i] - 9; l--) {
upd(dp[i + 1][j][l], dp[i][j][k] + calc(l, k)) ;
}
}
int ans = iinf ;
rep(i, 4, 51)
rep(j, 0, 47)
ans = min(ans, dp[n][i][j]) ;
// rep(i, 4, 51) {
// rep(j, 0, 47) cout << dp[n][i][j] << " " ;
// enter ;
// }
printf("%d\n", ans) ;
}
return 0 ;
}
/*
写代码时请注意:
1.ll?数组大小,边界?数据范围?
2.精度?
3.特判?
4.至少做一些
思考提醒:
1.最大值最小->二分?
2.可以贪心么?不行dp可以么
3.可以优化么
4.维护区间用什么数据结构?
5.统计方案是用dp?模了么?
6.逆向思维?
*/
标签:enter iterator test 思维 back func 贪心 min --
原文地址:https://www.cnblogs.com/harryhqg/p/10548887.html