非常有趣的构造题
看到这奇怪的数据范围就只要要依据这个搞事情
\(f(x+10^{18})=f(x)+1\)推而广之
\(\sum_{a-p}^{10^{18+a-p-1}}\equiv(mod\quad a)\)
且有\(\sum_{i=1}^{10^{18}-1}f(i)\equiv p(mod\quad a)\)
然后这个p可以推算得\(81*10^{18}mod\quad a\)
#include<cstdio>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cmath>
#include<stack>
#include<algorithm>
using namespace std;
template<class T>inline void read(T &x)
{
x=0;register char c=getchar();register bool f=0;
while(!isdigit(c))f^=c=='-',c=getchar();
while(isdigit(c))x=(x<<3)+(x<<1)+(c^48),c=getchar();
if(f)x=-x;
}
template<class T>inline void print(T x)
{
if(x<0)putchar('-'),x=-x;
if(x>9)print(x/10);
putchar('0'+x%10);
}
int t;
int a[2005];
int b[2005];
int n;
int f[2001][2001];
int main(){
read(n);
for(int i=1;i<=n;++i){
read(a[i]);
read(b[i]);
}
memset(f,0xc0,sizeof(f));
f[0][1]=0;
for(int i=1;i<=n;++i){
for(int j=0;j<=n;++j){
if(j+1>=a[i])
f[i][j]=max(f[i-1][j],f[i-1][j-a[i]+1]+b[i]);
else
f[i][j]=f[i-1][j];
if(j==a[i]){
f[i][j]=max(f[i][j],b[i]);
}
}
}
int ans=0;
for(int i=0;i<=n;++i){
ans=max(ans,f[n][i]);
}
cout<<ans;
return 0;
}