RT,这是一份正经的AC代码:
#include<bits/stdc++.h>
#define int1 long long
#define N 100000
using namespace std;
int1 c1,c2,c3,c4,t,d1,d2,d3,d4,e1,e2,e3,e4,s,dp[N + 5],ans,i;
int1 read(){
int1 x = 0,f = 1;
char ch = getchar();
while(!isdigit(ch)){
if(ch == '-'){
f = -1;
}
ch = getchar();
}
while(isdigit(ch)){
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
void uprint(int1 x){
if(x >= 10){
uprint(x / 10);
}
putchar(x % 10 ^ 48);
return ;
}
void print(int1 x){
if(x < 0){
putchar('-');
x = -x;
}
uprint(x);
return ;
}
void ps(int1 x){
print(x);
putchar(' ');
return ;
}
void pe(int1 x){
print(x);
putchar('\n');
return ;
}
int main(){
c1 = read(),c2 = read(),c3 = read(),c4 = read(),t = read();
dp[0] = 1;
for(i = c1; i <= N; i++){
dp[i] += dp[i - c1];
}
for(i = c2; i <= N; i++){
dp[i] += dp[i - c2];
}
for(i = c3; i <= N; i++){
dp[i] += dp[i - c3];
}
for(i = c4; i <= N; i++){
dp[i] += dp[i - c4];
}
while(t--){
d1 = read(),d2 = read(),d3 = read(),d4 = read(),s = read();
ans = dp[s];
e1 = (d1 + 1) * c1,e2 = (d2 + 1) * c2,e3 = (d3 + 1) * c3,e4 = (d4 + 1) * c4;
if(s >= e1){
ans -= dp[s - e1];
}
if(s >= e2){
ans -= dp[s - e2];
}
if(s >= e3){
ans -= dp[s - e3];
}
if(s >= e4){
ans -= dp[s - e4];
}
if(s >= e1 + e2){
ans += dp[s - e1 - e2];
}
if(s >= e1 + e3){
ans += dp[s - e1 - e3];
}
if(s >= e1 + e4){
ans += dp[s - e1 - e4];
}
if(s >= e2 + e3){
ans += dp[s - e2 - e3];
}
if(s >= e2 + e4){
ans += dp[s - e2 - e4];
}
if(s >= e3 + e4){
ans += dp[s - e3 - e4];
}
if(s >= e1 + e2 + e3){
ans -= dp[s - e1 - e2 - e3];
}
if(s >= e1 + e3 + e4){
ans -= dp[s - e1 - e3 - e4];
}
if(s >= e1 + e2 + e4){
ans -= dp[s - e1 - e2 - e4];
}
if(s >= e2 + e3 + e4){
ans -= dp[s - e2 - e3 - e4];
}
if(s >= e1 + e2 + e3 + e4){
ans += dp[s - e1 - e2 - e3 - e4];
}
pe(ans);
}
return 0;
}
然而我以前把 ans += dp[s - e1 - e2 - e3 - e4];
打成了 ans -= dp[s - e1 - e2 - e3 - e4];
还是AC……理论上这两个区别很大吧……