Advertisement
RaFiN_

how many continuous segment of sum zero

Aug 15th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. /* how many continuous segment of sum zero cf 383D  sign is not given we can take any sign on any number */
  2. ll dp[1001][20051],ans;ll arr[MAX];
  3.  
  4.  
  5. int main()
  6. {
  7.     booster()
  8.     //read("input.txt");
  9.  
  10.     int n;
  11.     cin>>n;
  12.     for(int i = 1;i<=n;i++)cin>>arr[i];
  13.     dp[0][0] = 1;
  14.     for(int i = 0;i<=n;i++)dp[i][0] = 1;
  15.     for(int i = 1;i<=n;i++){
  16.         for(int j = 0;j<=10000;j++){
  17.             if(j>=arr[i])
  18.             dp[i][j] += dp[i-1][j-arr[i]] + dp[i-1][j+arr[i]];
  19.             else dp[i][j] += dp[i-1][arr[i] - j] + dp[i-1][j+arr[i]];
  20.             if(dp[i][j]>=mod)dp[i][j]%=mod;
  21.         }
  22.         ans+=dp[i][0] - 1;
  23.         if(ans<0)
  24.         ans += mod;
  25.         if(ans>=mod)ans%=mod;
  26.     }
  27.  
  28.     cout<<ans;
  29.  
  30.  
  31.     return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement