cpp
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n, m;
struct use
{
int start;
int times;
int resum;
};
int const N = 2e5 + 10;
int arr[N];
vector<use>v[N];
int main()
{
cin >> n >> m;
for (int i = 1;i <= n;i++)
{
cin >> arr[i];
}
for (int i = 1;i <= m;i++)
{
int a, b, c, d;
cin >> a >> b >> c >> d;
int sum = arr[b];
/*for (int j = 0;j < v[b].size();j++)
{
if (v[b][j].start + v[b][j].times > a)
{
sum -= v[b][j].resum;
}
else
{
vector<use>::iterator it = v[b][j];
}
}*/
for (vector<use>::iterator it = v[b].begin();it != v[b].end();)
{
if ((*it).start+(*it).times>a)
{
sum -= (*it).resum;
it++;
}
else
{
vector<use>::iterator tmp = it;
it = v[b].erase(tmp);
}
}
sum -= d;
if (sum >= 0)
{
cout << sum << endl;
use u;
u.start = a;
u.times = c;
u.resum = d;
v[b].push_back(u);
}
else
{
cout << -1 << endl;
}
}
return 0;
}
cpp
#include<iostream>
using namespace std;
int n, m;
int const N = 50;
int dp[50][50];
int main()
{
cin >> n >> m;
dp[0][1] = 1;
for (int i = 1;i <= m;i++)
{
for (int j = 1;j <= n;j++)
{
if (j == 1)
{
dp[i][j] = dp[i - 1][2] + dp[i - 1][n];
}
else if (j == n)
{
dp[i][j] = dp[i - 1][n - 1] + dp[i - 1][1];
}
else
{
dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1];
}
}
}
cout << dp[m][1] << endl;
return 0;
}
cpp
#include<iostream>
#include<algorithm>
using namespace std;
int n, m;
int mod = 1e6 + 7;
int const N = 110;
int dp[N][N];
int arr[N];
int main()
{
cin >> n >> m;
dp[0][0] = 1;
for (int i = 1;i <= n;i++)
{
cin >> arr[i];
}
//表示前i个数总和为j的方案数
for (int i = 1;i <= n;i++)
{
for (int j = 0;j <= m;j++)
{
for (int k = 0;k <= min(arr[i], j);k++)
{
dp[i][j] = (dp[i][j] + dp[i - 1][j - k]) % mod;
}
}
}
cout << dp[n][m] << endl;
return 0;
}
cpp
#include<iostream>
using namespace std;
long long mod = 1e9 + 7;
long long d, t, m;
long long dp[3010][1510];
int main()
{
cin >> d >> t >> m;
//表示时间为 i,体力为j 的方案数
dp[0][m] = 1;
for (int i = 1;i <= t;i++)
{
for (int j = 0;j <= m;j++)
{
if ((m - j) * 2 - i + d > 0)
{
dp[i][j] = (dp[i - 1][j] + dp[i - 1][j + 1]) % mod;
}
}
}
cout << dp[t][0] << endl;
return 0;
}