A
点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 105;
#define ll long long
ll t, shu[N], n;
int main() {
cin >> t;
shu[1] = 1; shu[0] = 1;
for (int i = 2; i < 82; i++)
shu[i] = shu[i - 1] + shu[i - 2];
//cout << shu[80] << endl;
while (t--) {
cin >> n;
cout << shu[n] << endl;
}
return 0;
}
点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1e5 + 5, mod = 1e9 + 7;
int n, t;
long long shu[N];
void chu() {
shu[1] = 3; shu[2] = 9; shu[3] = 24;
for (int i = 4; i < N; i++) {
shu[i] = shu[i - 1] * 3 % mod;
shu[i] -= 2 * shu[i - 3];
shu[i] = (shu[i] +2* mod) % mod;
}
}
int main() {
chu();
cin >> t;
while (t--) {
cin >> n;
cout << shu[n] << endl;
}
return 0;
}
C
点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
const int n = 1e5 + 5, mod = 1e9 + 7;
ll n, t, dp[n];
void chu() {
for (ll i = 3; i < n; i++) {
if (i & 1)
dp[i] = dp[i / 2] + dp[i / 2 + 1] + 1;
else
dp[i] = dp[i / 2] * 2;
}
}
ll findd(ll n) {
if (n <= 100000) return dp[n];
if (n & 1)
return findd(n / 2) + findd(n / 2 + 1) + 1;
else
return 2 * findd(n / 2);
}
int main() {
chu();
cin >> t;
if (t == 1) {
cin >> n;
cout << findd(n) << endl;
}
else {
while (t--) {
cin >> n;
cout << dp[n] << endl;
}
}
return 0;
}
D
点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 1005;
int n, dp[N][N], a[N][N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 0; j <= i + 1; j++)
dp[i][j] = -1e9;
dp[1][1] = a[1][1];
for (int i = 2; i <= n; i++)
for (int j = 1; j <= i; j++)
dp[i][j] = max(dp[i - 1][j - 1] + a[i][j], dp[i - 1][j] + a[i][j]);
int rex = -1e9;
for (int i = 1; i <= n; i++) rex = max(rex, dp[n][i]);
cout << rex;
return 0;
}
G
点击查看代码
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
#define ll long long
const int N = 65;
ll n, t, dp1[N][N], dp2[N][N], shu[N][N];
string st[N];
ll gcd(ll a, ll b) {
return b ? gcd(b, a % b) : a;
}
int main() {
cin >> n >> t;
getchar();
for (int i = 1; i <= n; i++)
getline(cin, st[i]);
for (int i = 1; i <= n; i++) {
int k = 1;
// cout << st[i] << endl;
for (int j = 0; j < st[i].size(); j++)
if (st[i][j] == '*') shu[i][k++] = 0;
else if (st[i][j] == '.') shu[i][k++] = 1;
}
int k = 1, r = 1;
while (shu[k][r]) k += 2, r++;
dp1[k][r] = 1; dp2[k][r] = 1;
for (int i = k; i <= n; i++) {
for (int j = 1; j <=i; j++) {
if (i != n + 1 && shu[i][j] == 1) dp1[i + 2][j + 1] += 4 * dp1[i][j];
else dp1[i + 1][j + 1] += dp1[i][j], dp1[i + 1][j] += dp1[i][j];
//cout << dp1[i][j] << ' ';
}
//cout << endl;
}
ll p = 1; dp2[n+1][t+1] = pow(2, n+1 - k);
if (dp1[n + 1][t + 1] == 0) dp2[n + 1][t + 1] = 1;
else p = gcd(dp1[n + 1][t + 1], dp2[n + 1][t + 1]);
cout << dp1[n + 1][t + 1] / p << '/' << dp2[n + 1][t + 1] / p ;
return 0;
}
H
点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 30;
long long qi[N][N], dp[N][N];
int n, m, x, y;
int X[8]{ 2,2,1,1,-1,-1,-2,-2 }, Y[8]{ 1,-1,2,-2,2,-2,1,-1 };
int main() {
cin >> n >> m >> x >> y;
n += 2, m += 2, x += 2, y += 2;
qi[x][y] = 1;
//cout << x << ' ' << y << endl;
for (int i = 0; i < 8; i++)
if (x + X[i] >= 0 && y + Y[i] >= 0)
qi[x + X[i]][y + Y[i]] = 1;
dp[2][2] = 1;
for (int i = 2; i <= n; i++)
{
for (int j = 2; j <= m; j++) {
if (i == 2 && j == 2||qi[i][j] == 1) continue;
else dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
//cout << dp[i][j] << ' ';
}
//cout << endl;
}
cout << dp[n][m];
return 0;
}
Q
点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int v, n, dp[20005];
int shu[35];
int main() {
cin >> v >> n;
for (int i = 1; i <= n; i++)
cin >> shu[i];
for (int i = 1; i <= n; i++) {
if (shu[i] > v) continue;
for (int j = v; j >= shu[i]; j--)
dp[j]=max(dp[j],dp[j - shu[i]] + shu[i]);
}
cout << v - dp[v];
return 0;
}
R
点击查看代码
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 1e3 + 5;
int shu[N], w[N], n, m;
int dp[N];
int main() {
memset(dp, 0, sizeof(dp));
cin >> n >> m;
for (int i = 1; i <= m; i++)
cin >> shu[i] >> w[i];
for (int i = 1; i <= m; i++)
for (int j = n; j >= shu[i]; j--)
dp[j] = max(dp[j], dp[j - shu[i]] + w[i]);
cout << dp[n];
return 0;
}
S
点击查看代码
//#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
int V, n;
int v[35],p;
ll w[35], dp[20005];
int main() {
cin >> V >> n;
for (int i = 1; i <= n; i++){
cin >> v[i] >> p;
w[i] = v[i] * p;
}
for (int i = 1; i <= n; i++)
for (int j = V; j >= v[i]; j--)
dp[j]=max(dp[j],dp[j - v[i]] + w[i]);
cout << dp[V];
return 0;
}