Skip to content

Commit 53448ae

Browse files
committed
update changes
1 parent 4f1359a commit 53448ae

File tree

70 files changed

+4036
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+4036
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.sass-cache/
2+
_site/
3+

CODE_OF_CONDUCT.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our Standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
* Using welcoming and inclusive language
12+
* Being respectful of differing viewpoints and experiences
13+
* Gracefully accepting constructive criticism
14+
* Focusing on what is best for the community
15+
* Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
* The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
* Trolling, insulting/derogatory comments, and personal or political attacks
21+
* Public or private harassment
22+
* Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
* Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our Responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at codeiiest@gmail.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44+
45+
[homepage]: http://contributor-covenant.org
46+
[version]: http://contributor-covenant.org/version/1/4/

CONTRIBUTING.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Contribution guidelines
2+
3+
First of all, thanks for thinking of contributing to this project. :smile:
4+
5+
Before sending a Pull Request, please make sure that you're assigned the task on a GitHub issue.
6+
7+
- If a relevant issue already exists, discuss on the issue and get it assigned to yourself on GitHub.
8+
- If no relevant issue exists, open a new issue and get it assigned to yourself on GitHub.
9+
10+
Please proceed with a Pull Request only after you're assigned. It'd be sad if your Pull Request (and your hardwork) isn't accepted just because it isn't ideologically compatible.
11+
12+
While making a Pull Request, please take care of the following rules:
13+
14+
- Make sure the master branch of your forked repo is not any commits ahead than the original master repository.
15+
- Create a new branch from master in the forked repository. Updated your changes in that branch and not in master.
16+
- Include only one algorithm in each pull request. A PR containing more than one algorithm *will not be merged*.
17+
- Write your algorithm in a language other coders are mostly acquainted with i.e. `C`/`C++`/`Python`/`Java`. Any
18+
other language will be accepted only after discussion with the maintainers.
19+
- When writing the algorithm's code, please include a small `readme.md` file in the folder briefly explaining the
20+
algorithm. Make sure your `readme.md` provides a clear understanding of the algorithm to a new-comer. Explanation
21+
should be given in not more than 300 characters
22+
- Write the name of the algorithm you added and the language you used in the title while making the PR.
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// A Backtracking program in C++ to solve Sudoku problem
2+
#include <stdio.h>
3+
4+
// UNASSIGNED is used for empty cells in sudoku grid
5+
#define UNASSIGNED 0
6+
7+
// N is used for size of Sudoku grid. Size will be NxN
8+
#define N 9
9+
10+
// This function finds an entry in grid that is still unassigned
11+
bool FindUnassignedLocation(int grid[N][N], int &row, int &col);
12+
13+
// Checks whether it will be legal to assign num to the given row,col
14+
bool isSafe(int grid[N][N], int row, int col, int num);
15+
16+
/* Takes a partially filled-in grid and attempts to assign values to
17+
all unassigned locations in such a way to meet the requirements
18+
for Sudoku solution (non-duplication across rows, columns, and boxes) */
19+
bool SolveSudoku(int grid[N][N])
20+
{
21+
int row, col;
22+
23+
// If there is no unassigned location, we are done
24+
if (!FindUnassignedLocation(grid, row, col))
25+
return true; // success!
26+
27+
// consider digits 1 to 9
28+
for (int num = 1; num <= 9; num++)
29+
{
30+
// if looks promising
31+
if (isSafe(grid, row, col, num))
32+
{
33+
// make tentative assignment
34+
grid[row][col] = num;
35+
36+
// return, if success, yay!
37+
if (SolveSudoku(grid))
38+
return true;
39+
40+
// failure, unmake & try again
41+
grid[row][col] = UNASSIGNED;
42+
}
43+
}
44+
return false; // this triggers backtracking
45+
}
46+
47+
/* Searches the grid to find an entry that is still unassigned. If
48+
found, the reference parameters row, col will be set the location
49+
that is unassigned, and true is returned. If no unassigned entries
50+
remain, false is returned. */
51+
bool FindUnassignedLocation(int grid[N][N], int &row, int &col)
52+
{
53+
for (row = 0; row < N; row++)
54+
for (col = 0; col < N; col++)
55+
if (grid[row][col] == UNASSIGNED)
56+
return true;
57+
return false;
58+
}
59+
60+
/* Returns a boolean which indicates whether any assigned entry
61+
in the specified row matches the given number. */
62+
bool UsedInRow(int grid[N][N], int row, int num)
63+
{
64+
for (int col = 0; col < N; col++)
65+
if (grid[row][col] == num)
66+
return true;
67+
return false;
68+
}
69+
70+
/* Returns a boolean which indicates whether any assigned entry
71+
in the specified column matches the given number. */
72+
bool UsedInCol(int grid[N][N], int col, int num)
73+
{
74+
for (int row = 0; row < N; row++)
75+
if (grid[row][col] == num)
76+
return true;
77+
return false;
78+
}
79+
80+
/* Returns a boolean which indicates whether any assigned entry
81+
within the specified 3x3 box matches the given number. */
82+
bool UsedInBox(int grid[N][N], int boxStartRow, int boxStartCol, int num)
83+
{
84+
for (int row = 0; row < 3; row++)
85+
for (int col = 0; col < 3; col++)
86+
if (grid[row+boxStartRow][col+boxStartCol] == num)
87+
return true;
88+
return false;
89+
}
90+
91+
/* Returns a boolean which indicates whether it will be legal to assign
92+
num to the given row,col location. */
93+
bool isSafe(int grid[N][N], int row, int col, int num)
94+
{
95+
/* Check if 'num' is not already placed in current row,
96+
current column and current 3x3 box */
97+
return !UsedInRow(grid, row, num) &&
98+
!UsedInCol(grid, col, num) &&
99+
!UsedInBox(grid, row - row%3 , col - col%3, num);
100+
}
101+
102+
/* A utility function to print grid */
103+
void printGrid(int grid[N][N])
104+
{
105+
for (int row = 0; row < N; row++)
106+
{
107+
for (int col = 0; col < N; col++)
108+
printf("%2d", grid[row][col]);
109+
printf("\n");
110+
}
111+
}
112+
113+
/* Driver Program to test above functions */
114+
int main()
115+
{
116+
// 0 means unassigned cells
117+
int grid[N][N] = {{3, 0, 6, 5, 0, 8, 4, 0, 0},
118+
{5, 2, 0, 0, 0, 0, 0, 0, 0},
119+
{0, 8, 7, 0, 0, 0, 0, 3, 1},
120+
{0, 0, 3, 0, 1, 0, 0, 8, 0},
121+
{9, 0, 0, 8, 6, 3, 0, 0, 5},
122+
{0, 5, 0, 0, 9, 0, 6, 0, 0},
123+
{1, 3, 0, 0, 0, 0, 2, 5, 0},
124+
{0, 0, 0, 0, 0, 0, 0, 7, 4},
125+
{0, 0, 5, 2, 0, 6, 3, 0, 0}};
126+
if (SolveSudoku(grid) == true)
127+
printGrid(grid);
128+
else
129+
printf("No solution exists");
130+
131+
return 0;
132+
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* C/C++ program to solve N Queen Problem using backtracking */
2+
#define N 4
3+
#include<stdio.h>
4+
5+
/* A utility function to print solution */
6+
void printSolution(int board[N][N])
7+
{
8+
for (int i = 0; i < N; i++)
9+
{
10+
for (int j = 0; j < N; j++)
11+
printf(" %d ", board[i][j]);
12+
printf("\n");
13+
}
14+
}
15+
16+
/* A utility function to check if a queen can
17+
be placed on board[row][col]. Note that this
18+
function is called when "col" queens are
19+
already placed in columns from 0 to col -1.
20+
So we need to check only left side for
21+
attacking queens */
22+
bool isSafe(int board[N][N], int row, int col)
23+
{
24+
int i, j;
25+
26+
/* Check this row on left side */
27+
for (i = 0; i < col; i++)
28+
if (board[row][i])
29+
return false;
30+
31+
/* Check upper diagonal on left side */
32+
for (i=row, j=col; i>=0 && j>=0; i--, j--)
33+
if (board[i][j])
34+
return false;
35+
36+
/* Check lower diagonal on left side */
37+
for (i=row, j=col; j>=0 && i<N; i++, j--)
38+
if (board[i][j])
39+
return false;
40+
41+
return true;
42+
}
43+
44+
/* A recursive utility function to solve N Queen problem */
45+
bool solveNQUtil(int board[N][N], int col)
46+
{
47+
/* base case: If all queens are placed then return true */
48+
if (col >= N)
49+
return true;
50+
51+
/* Consider this column and try placing this queen in all rows one by one */
52+
for (int i = 0; i < N; i++)
53+
{
54+
/* Check if queen can be placed on board[i][col] */
55+
if ( isSafe(board, i, col) )
56+
{
57+
/* Place this queen in board[i][col] */
58+
board[i][col] = 1;
59+
60+
/* recur to place rest of the queens */
61+
if ( solveNQUtil(board, col + 1) )
62+
return true;
63+
64+
/* If placing queen in board[i][col] doesn't lead to a solution, then remove queen from board[i][col] */
65+
board[i][col] = 0; // BACKTRACK
66+
}
67+
}
68+
69+
/* If queen can not be place in any row in this colum col then return false */
70+
return false;
71+
}
72+
73+
/* This function solves the N Queen problem using
74+
Backtracking. It mainly uses solveNQUtil() to
75+
solve the problem. It returns false if queens
76+
cannot be placed, otherwise return true and
77+
prints placement of queens in the form of 1s.
78+
Please note that there may be more than one
79+
solutions, this function prints one of the
80+
feasible solutions.*/
81+
bool solveNQ()
82+
{
83+
int board[N][N] = { {0, 0, 0, 0},
84+
{0, 0, 0, 0},
85+
{0, 0, 0, 0},
86+
{0, 0, 0, 0}
87+
};
88+
89+
if ( solveNQUtil(board, 0) == false )
90+
{
91+
printf("Solution does not exist");
92+
return false;
93+
}
94+
95+
printSolution(board);
96+
return true;
97+
}
98+
99+
// driver program to test above function
100+
int main()
101+
{
102+
solveNQ();
103+
return 0;
104+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Two 1-d array implementation
2+
#include <bits/stdc++.h>
3+
using namespace std;
4+
const int inf=0x3fffffff;
5+
#define Min(a,b) (a<b?a:b)
6+
#define Max(a,b) (a<b?b:a)
7+
#define fr(i,j,s) for(i = j ; i < s ; i++)
8+
long long int current_dp[100002]={0};
9+
long long int previous_dp[100002]={0};
10+
int main(void)
11+
{
12+
long long int test ,alpha , temp , lena , lenb , i, j,z,x,c ;
13+
char a[100001];
14+
char b[100001];
15+
cin>>test ;
16+
while(test--)
17+
{
18+
cin>>a;
19+
cin>>b;
20+
cin>>z;
21+
cin>>x;
22+
cin>>c;
23+
lena = strlen(a) ;
24+
lenb = strlen(b) ;
25+
if((lena-lenb)*z > c || (lenb-lena)*z > c )
26+
{
27+
cout<<"-1\n";
28+
continue ;
29+
}
30+
if( (z == 0) )
31+
{
32+
cout<<"0\n" ;
33+
continue ;
34+
}
35+
if( (x == 0) )
36+
{
37+
cout<<z*((lena-lenb) < 0 ? -1*(lena-lenb):(lena-lenb))<<"\n" ;
38+
continue ;
39+
}
40+
fr(i,0,lenb+1)
41+
{
42+
if(i > c)
43+
previous_dp[i] = inf ;
44+
else
45+
previous_dp[i] = i*z ;
46+
}
47+
fr(i,1,lena+1)
48+
{
49+
alpha = Max((i-c),0) ;
50+
if( alpha > 0)
51+
{
52+
current_dp[alpha-1] = inf ;
53+
}
54+
alpha -= 1 ;
55+
temp = Min((i+c+1),(lenb+1));
56+
fr(j,alpha+1,temp)
57+
{
58+
if(j == 0)
59+
{
60+
current_dp[j] = i*z ;
61+
}
62+
else
63+
{
64+
current_dp[j] = Min(Min(previous_dp[j] + z , current_dp[j-1] + z ) , previous_dp[j-1]+(a[i-1] == b[j-1] ? 0 : x));
65+
}
66+
}
67+
fr(j,alpha,temp)
68+
{
69+
previous_dp[j] = current_dp[j] ;
70+
}
71+
}
72+
if(current_dp[lenb] > c)
73+
cout<<"-1\n";
74+
else
75+
cout<<current_dp[lenb]<<"\n";
76+
}
77+
return 0 ;
78+
}

0 commit comments

Comments
 (0)