luyencode / comments

Server lưu trữ bình luận trên Luyện Code
https://luyencode.net
6 stars 3 forks source link

https://oj.luyencode.net/problem/GACON #902

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

Gà Con - Luyện Code Online

https://oj.luyencode.net/problem/GACON

tu102 commented 1 year ago

Kết quả của e đều đúng mà em nộp cứ bị WA ạ. Mọi người ai có lời giải bài này không ạ?

tu102 commented 1 year ago

include

using namespace std; long a[1005][1005]; int huong[3][2]={{1,-1},{1,0},{1,1}}; int main(){ //freopen("input.txt","r",stdin); int n,m; cin>>n>>m; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ cin>>a[i][j]; } } for(int j=0;j<m;j++){ int x=0,y=j; while(1){ int max=0; int xx,yy; for(int k=0;k<3;k++){ int xmax = x + huong[k][0]; int ymax = y + huong[k][1]; if(xmax<n&&xmax>=0&&ymax>=0&&ymax<m){ if(a[xmax][ymax]>max){ max = a[xmax][ymax]; xx =xmax; yy= ymax; } } } a[0][j]=a[0][j]+max; x=xx; y=yy; if(x==n-1){ break; } } } int max2=0; for(int j=0;j<m;j++){ if(a[0][j]>max2){ max2=a[0][j]; } }

        cout<<max2<<endl;
return 0;

}

quanghuy121 commented 1 year ago
Xem code AC ```cpp #include using namespace std; #define maxn 1004 #define ll long long ll f[maxn][maxn]; int a[maxn][maxn]; ll maxf(ll a, ll b) { if (a>b) return a; return b; } int main(){ int n, m; cin >> n >> m; for (int i = 1; i<=n; i++){ for (int j = 1; j<=m; j++){ cin >> a[i][j]; } } ll res = 0; memset(f,0,sizeof(f)); for (int i = 1; i<=n; i++){ for (int j = 1; j<=m; j++){ f[i][j] = maxf(f[i-1][j-1] + a[i][j], maxf(f[i-1][j] + a[i][j], f[i-1][j+1] + a[i][j])); res = maxf(f[i][j], res); } } cout << res; } ```