Daliy Algorithm (数学,dp)-- day 73
Nothing to fear
种一棵树最好的时间是十年前,其次是现在!
那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~
2020.5.6
人一我十, 人十我百,追逐青春的梦想,怀着自信的心,永不言弃!
Basketball Exercise
线性dp
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <ctime>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
#define x first
#define y second
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
const int N = 100005;
int t;
ll max(ll a , ll b)
{
if(a > b)return a;
else return b;
}
void slove()
{
int n;
cin >> n;
vector<int> a(n + 1),b(n + 1);
for(int i = 1;i <= n ;i ++)cin >> a[i];
for(int i = 1;i <= n ;i ++)cin >> b[i];
ll f[4][N];
memset(f , 0 , sizeof f);
for(int i = 1;i <= n ;i ++)
{
f[1][i] = max(max(a[i],a[i] + f[2][i-1]),f[3][i-1] + a[i]);
f[2][i] = max(max(b[i],b[i] + f[1][i-1]),f[3][i-1] + b[i]);
f[3][i] = max(f[1][i-1],f[2][i-1]);
}
cout << max(f[1][n],f[2][n]) << endl;
}
int main()
{
SIS;
slove();
}
Fillinig shapes
数学推理题,要注意精度
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
int t;
void slove()
{
int n;
cin >> n;
if(n & 1)cout << 0 << endl;
else {
ll ans = 1;
for(int i = 1;i <= n / 2; i++)
{
ans = ans * 2;
}
cout << ans << endl;
}
}
int main()
{
#ifdef LOCAL
auto start_time = clock();
cerr << setprecision(3) << fixed;
#endif
SIS;
slove();
#ifdef LOCAL
auto end_time = clock();
cerr << "Execution time: " << (end_time - start_time) * (int)1e3 / CLOCKS_PER_SEC << " ms\n";
#endif
}
luogu-P1435 回文字串
如何求解最少需要改动的地方实际上就是将这个字串倒过来
观察那些地方不一样,总长度减去两个字符串的最长公共子序列。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 1005;
char a[N] , b[N];
int f[N][N];
int main()
{
cin >> a + 1;
int n = strlen(a + 1);
for(int i = 1 ;i <= n;i++)
b[i] = a[n-i+1];
for(int i = 1;i <= n ;i ++)
{
for(int j = 1;j <= n ;j ++)
{
if(a[i] == b[j])
{
f[i][j] = f[i-1][j-1] + 1;
}else f[i][j] = max(f[i-1][j],f[i][j-1]);
}
}
cout << n - f[n][n] << endl;
return 0;
}