2189 digital triangle W, 2189 triangle w
2189 digital triangle W
Time Limit: 1 s space limit: 32000 KB title level: Gold Title Description
Description
Digital triangle
The maximum number of mod 100 is required.
Input description
Input Description
Row n, indicating n
2nd to n + 1 actions each weight
Output description
Output Description
Maximum mod 100
Sample Input
Sample Input
2
1
99 98
Sample output
Sample Output
99
Data range and prompt
Data Size & Hint
N <= 25
CATEGORY tag
Tags click here to expand
The number of last one-dimensional records % p may not be reached
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 const int MAXN=26; 6 int n; 7 int a[MAXN][MAXN]; 8 bool f[MAXN][MAXN][101]; 9 int main()10 {11 scanf("%d",&n);12 for(int i=1;i<=n;i++)13 for(int j=1;j<=i;j++)14 cin>>a[i][j];15 16 for(int i=1;i<=n;i++)f[n][i][a[n][i]%100]=1;17 18 for(int i=n-1;i>=1;i--)19 for(int j=1;j<=i;j++)20 for(int k=0;k<=99;k++)21 f[i][j][k]=f[i+1][j][(k-a[i][j]+100)%100]||f[i+1][j+1][(k-a[i][j]+100)%100];22 23 for(int k=100;k>=1;k--)24 if(f[1][1][k]==1){cout<<k;break;}25 return 0;26 }