Nothing to fear
种一棵树最好的时间是十年前,其次是现在!
那些你早出晚归付出的刻苦努力,你不想训练,当你觉的太累了但还是要咬牙坚持的时候,那就是在追逐梦想,不要在意终点有什么,要享受路途的过程,或许你不能成就梦想,但一定会有更伟大的事情随之而来。 mamba out~
2020.5.3
人一我十, 人十我百,追逐青春的梦想,怀着自信的心,永不言弃!
Road To Zero
#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()
{
ll x , y , a , b;
cin >> x >> y >> a >> b;
if(x == 0 && y == 0)
{
cout << 0 << endl;
return ;
}else
{
if(x < y)swap(x , y);
// 首先保证 X >= y
if(2*a <= b)
{
cout << (x + y) * a << endl;
}else cout << y*b + (x - y) * a << endl;
return;
}
}
int main()
{
SIS;
cin >> t;
while(t--)
{
slove();
}
}
train
一个还不错得思维题目,将问题分为两种极端边界情况。
从这两种情况乱各种直接筛选出来最优解。
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <cmath>
#include <map>
#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;
map<int,int> m;
void slove()
{
int n;
cin >> n;
vector<int> a(n + 1);
int x = 0;
int diff = 0,cnt = 0;
for (int i = 1; i <= n; ++i)
{
cin >> x;
if(a[x] == 0)diff++;
a[x]++;cnt = max(cnt , a[x]);
}
int ans = max(min(diff - 1,cnt),min(diff,cnt - 1));
cout << ans << endl;
return ;
}
int main()
{
SIS;
cin >> t;
while(t--)
{
slove();
}
}
杨老师得照相排列
多维度线性dp经典好题 值得做N遍
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
using namespace std;
const int N = 31;
typedef long long ll;
ll f[N][N][N][N][N];
int main()
{
int n;
while(cin >> n , n)
{
memset(f , 0 , sizeof f);
int s[5] = {0};
// 输入每一排得人数
for(int i = 0;i < n; i++)cin >> s[i];
f[0][0][0][0][0] = 1;
for(int a = 0;a <= s[0] ;a ++)
for(int b = 0;b <= min(a , s[1]); b ++)
for(int c = 0;c <= min(b , s[2]); c++)
for(int d = 0;d <= min(c ,s[3]); d++)
for(int e = 0;e <= min(d , s[4]); e++)
{
ll &x = f[a][b][c][d][e];
if(a && a - 1 >= b)x += f[a-1][b][c][d][e];
if(b && b - 1 >= c)x += f[a][b-1][c][d][e];
if(c && c - 1 >= d)x += f[a][b][c-1][d][e];
if(d && d - 1 >= e)x += f[a][b][c][d-1][e];
if(e) x += f[a][b][c][d][e-1];
}
cout << f[s[0]][s[1]][s[2]][s[3]][s[4]] << endl;
}
return 0;
}
onstanze's machine
就简单dp, 用来入门蛮不错的一道题
#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;
const int mod = 1e9 + 7;
int t;
void slove(string s)
{
//首先检查存不存在 m 或者 w
int n = s.size();
for(int i = 0;i < n ;i ++)
{
if(s[i] == 'w' || s[i] == 'm')
{
cout << 0 << endl;
return;
}
}
vector<int> f(n + 1);
f[0] = 1,f[1] = 1;
for(int i = 2; i <= n;i ++)
{
f[i] = f[i-1];
if(s[i-1] == s[i-2] && (s[i-1] == 'u' || s[i-1] == 'n'))
{
f[i] = (f[i] + f[i-2]) % mod;
}
}
cout << f[n] << endl;
}
int main()
{
SIS;
string s;
while(cin >> s)
{
slove(s);
}
}