2023.10.01 日记

发布时间 2023-10-01 21:47:19作者: xiehanrui0817

1 + 1 = 2

\(f[i]\)\(a+b=i\) 的和。

显然可得 \(f[a]=f[a-b]+f[b],f[1]=1\)

所以可得 \(1+1=f[1]+f[1]=f[2]=2\)

code

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a,b,f[maxn];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  cin>>a>>b;
  f[1]=1;
  for(int i=2;i<=a+b;i++){
    for(int j=1;j<=i;j++){
      f[i]=max(f[i],f[i-j]+f[j]);
    }
  }
  cout<<f[a+b];
  return 0;
}