【K题】Guanguan's Happy water
Meaning of the questions: in fact, seeking first k expectations of the current node
N for two cases:
1.n <= k ----- directly applied to a [1 ... n]
2.n>k----ans=suma+f[k+1...n]
Note that most of the data types which: important to note, all possible modulo modulus can
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int maxn=77; const ll mod=1e9+7; ll a[maxn],f[maxn]; int main() { int t; scanf("%d",&t); int k; ll n; while(t--){ scanf("%d%lld",&k,&n); ll suma=0,sumf=0; for(int i=1;i<=k;i++){ scanf("%lld",&a[i]); suma=(suma+a[i])%mod; } for(int i=1;i<=k;i++){ scanf("%lld",&f[i]); sumf=(sumf+f[i])%mod; } ll ans=0; if(n<=k){ for(inti = 1 ; i <= ( int ) n; i ++ ) ans = (ANS + a [i])% v; } Else { ans = suma% v; ll cnt = (nk) / k; int len = cnt n-k * k; cnt % = v; ans = (cnt * sumf + ANS)% v; for ( int i = 1 ; i <= len; ++ i) ans = (ANS + F [i])% v; } Printf ( " % lld \ n" , Year% change); } }
//#pragma GCC optimize(2) #include <bits/stdc++.h> using namespace std; #define _ 0 #define MX 100050 #define pb push_back #define len length() #define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); typedef long long ll; typedef pair <int,int> iip; int i, j, cnt = 0; ll dp[MX]; int main() { // IO int n, m; while(scanf("%d%d", &n, &m) != EOF) { dp[0] = 0; for(int i = 1; i <= m+10000; i++) { dp[i] = 0x1f1f1f1f1f1f1f1f; } for(int k = 0; k < n; k++) { ll p, c; scanf("%lld%lld", &p, &c); for(int i = c; i <= m+10000; i++) { dp[i] = min(dp[i-c]+p, dp[i]); } } ll a = 0x1f1f1f1f1f1f1f1f, b = m; for(int i = m; i <= m+10000; i++) { if(dp[i] <= a) a = dp[i], b = i; } printf("%lld %lld\n", a, b); } return ~~(0^_^0); }