B. I. O. U.
Question link: Click the open link
Ideas:
The minimum debts in a link is the sum or the sum of the given values.
Ps: the data on this question seems to be very watery, and a lot of code is too watery...
Code:
#include
#include
#include
#include #include
#include
#include
#include
#include
#include
#include
#pragma comment (linker,/STACK:102400000,102400000)#define maxn 1005#define MAXN 100005#define mod 1000000007#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;int n,m,ans,flag,cnt,best;int in[maxn],out[maxn];void solve(){ int i,j,t; ans=0; for(i=1;i<=n;i++) { ans+=max(0,in[i]-out[i]); }}int main(){ int i,j,t,pos,x,y,u,v,w; while(~scanf(%d%d,&n,&m)) { memset(in,0,sizeof(in)); memset(out,0,sizeof(out)); for(i=1;i<=m;i++) { scanf(%d%d%d,&u,&v,&w); out[u]+=w; in[v]+=w; } solve(); printf(%d,ans); } return 0;}/*3 31 2 22 3 33 1 47 51 2 102 3 12 4 14 1 56 7 8*/
C. Divisible by Seven
Question link: Click the open link
Idea: extract values 1, 6, 8, and 9. Because 1689 can be obtained for all the remainder except 7, you can put other numbers at the beginning, then we can use the 1689 arrangement to add the missing values. For example, if xxxP % 7 = (xxx0000% 7) + (P % 7) % 7 and the remainder of xxx0000 % 7 is 5, then construct a P so that (P % 7) more than 2 will be able to make this number be divisible by 7.
Ps: of course, there cannot be a leading 0, so there must be a small case.
Thoughts:
This constructor is used during the competition, but I put the 1689 arrangement in the front to construct the Pxxx format, which makes the processing complex and cannot be constructed in this way, so there is no end to WA...
Code:
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Pragma comment (linker,/STACK: 102400000,102400000) # define maxn 1005 # define MAXN 100005 # define mod 1000000007 # define INF 0x3f3f3f # define pi acos (-1.0) # define eps 1e-6typedef long ll; using namespace std; int n, m, ans, flag; bool vis [10]; string fac [7] = {1869,1968, 1689,619 8, 8916,1896}; string s, ss, anss, xx = 0000; int main () {int I, j, t, pos, x, y, u, v, w; while (cin> s) {memset (vis, 0, sizeof (vis); ss =; for (I = 0; I
D. Maximum Submatrix 2
Question link: Click the open link
Ideas:
Because rows can be exchanged and Columns cannot be exchanged, the number on the left side of each number cannot be changed.
Construct a dp [I] [j] to indicate the number of consecutive 1 in front of the position j in row I.
Then we will analyze the form of the optimal solution without any exchange. It must be that each row has several consecutive 1 s, and then it forms the largest matrix.
Then we construct another cnt [col] [j], record the number of the first 1 in the col column> = the number of lines in the j column, the maximum value can be updated in dp [I] [j] * cnt [j] [dp [I] [j.
Code:
#include
#include
#include
#include #include
#include
#include
#include
#include
#include
#include
#pragma comment (linker,/STACK:102400000,102400000)#define maxn 5005#define MAXN 100005#define mod 1000000007#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;int n,m,ans;char mp[maxn][maxn];int dp[maxn][maxn],cnt[maxn][maxn];void presolve(){ int i,j,t; memset(cnt,0,sizeof(cnt)); for(i=1;i<=n;i++) { dp[i][0]=0; for(j=1;j<=m;j++) { if(mp[i][j]=='1') dp[i][j]=dp[i][j-1]+1; else dp[i][j]=0; cnt[j][dp[i][j]]++; } } for(int col=m;col>=1;col--) { for(j=m;j>=1;j--) { cnt[col][j]+=cnt[col][j+1]; } }}void solve(){ int i,j,t; ans=0; for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { t=dp[i][j]*cnt[j][dp[i][j]]; ans=max(ans,t); } }}int main(){ int i,j,t; while(~scanf(%d%d,&n,&m)) { for(i=1;i<=n;i++) { scanf(%s,mp[i]+1); } presolve(); solve(); printf(%d,ans); } return 0;}/*4 71001111111001001110010110011*/