Placed flowers
[Solving] report
Typical dp Evaluating the number of issues.
First on the search Dafa
(Ah, the beautiful memories search! He can actually A data range is too small a thing)
(在luogu题解搞的代码_(:3_|/_)_
#include<bits/stdc++.h>
#define mod 1000007
const int N = 1005;
int n, m, a[N],jy[N][N];
int dfs(int x,int k){
int ans = 0;
if(k > m) return 0;
if(k == m) return 1;
if(x == n+1) return 0;
if(jy[x][k]) return jy[x][k];
for(int i = 0; i <= a[x]; i++) ans = (ans + dfs(x+1, k+i)) % mod;
jy[x][k] = ans;
return ans;
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++) scanf("%d",a + i);
printf("%d",dfs(1,0));
return 0;
}
Deep into the ♂ ♂ ♂ sub-analysis of the problem
(Feeling positive solution than the search for good writing ah ......emm, after all, dynamic programming ah ......)
\ (f [i] [j ] \) represent now put the first \ (i \) potted plant, we have put a \ (j \) platter.
(For those familiar with this definition dp students should be in terms mouth came (fog)
For this dp, we can consider two optimization: an array of rolling and backpack.
----------------------------------------- unfinished ------- ------------------------------------------------