update
This commit is contained in:
parent
9e28b0004c
commit
686de13f1b
34
src/11/29/P1077/P1077.cpp
Normal file
34
src/11/29/P1077/P1077.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
|
||||
typedef long long ll;
|
||||
|
||||
const int MOD = 1000007;
|
||||
|
||||
int main(){
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
vector<int> a(n);
|
||||
for(auto &x: a) cin >> x;
|
||||
|
||||
// dp[j] 表示当前总数为 j 的方案数
|
||||
vector<int> dp(m+1, 0);
|
||||
dp[0] = 1;
|
||||
|
||||
for(int i=0; i<n; ++i){
|
||||
// 创建一个新的临时数组来存储更新后的值
|
||||
vector<int> new_dp(m+1, 0);
|
||||
for(int j=0; j<=m; ++j){
|
||||
if(dp[j] == 0) continue;
|
||||
// 尝试摆放 k 盆当前类型的花
|
||||
for(int k=0; k<=a[i] && j + k <= m; ++k){
|
||||
new_dp[j + k] = (new_dp[j + k] + dp[j]) % MOD;
|
||||
}
|
||||
}
|
||||
dp = new_dp;
|
||||
}
|
||||
|
||||
cout << dp[m] % MOD;
|
||||
return 0;
|
||||
}
|
45
src/11/29/P4084/P4084.cpp
Normal file
45
src/11/29/P4084/P4084.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
using namespace std;
|
||||
using ll = int64_t;
|
||||
|
||||
ll const maxn{2500+5};
|
||||
ll n,ans;
|
||||
array<ll,maxn> t,tmp;
|
||||
vector<ll> adj[maxn];
|
||||
|
||||
void dfs(ll const& ftr, ll const& u){
|
||||
for(ll const& v:adj[u]){
|
||||
if(v==ftr)continue;
|
||||
dfs(u,v);
|
||||
tmp[u]+=12-tmp[v];
|
||||
tmp[u]%=12;
|
||||
if(tmp[u]==0)tmp[u]=12;
|
||||
}
|
||||
}
|
||||
|
||||
int main(){
|
||||
cin.tie(nullptr),cout.tie(nullptr),ios::sync_with_stdio(false);
|
||||
|
||||
cin>>n;
|
||||
for(ll i{1};i<=n;i++)cin>>t[i];
|
||||
for(ll i{1};i<n;i++){
|
||||
ll u,v;
|
||||
cin>>u>>v;
|
||||
adj[u].emplace_back(v);
|
||||
adj[v].emplace_back(u);
|
||||
}
|
||||
|
||||
for(ll i{1};i<=n;i++){
|
||||
copy(t.data(),t.data()+1+n,tmp.data());
|
||||
dfs(0,i);
|
||||
if(tmp[i]==12||tmp[i]==1){
|
||||
ans++;
|
||||
}
|
||||
}
|
||||
cout<<ans<<'\n';
|
||||
}
|
Loading…
Reference in New Issue
Block a user